今天项目需要交接,由于Google App Engine 的 JPA实现,需要 Enhancer ,默认的Eclipse插件会Enhance编译所有的 class,倒是一个错误;
可以的办法是 手动设置 Enhancer的参数,然后手动Enhancer编译,还有的办法就是官方提供的Ant 或者 Maven插件编译。
捣鼓了小半天,
搞定了一些问题,,终于运行项目到发布,在此记录一下,希望可以帮助有同样问题的IT工作者。
1. Ant 默认 编译器 面对 Annotation中使用了 枚举的编译错误
/**
*
* Define annotation for BespokeReference
*
*
@author
zx
*
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public
@
interface
BReference {
/**
*
*
@return
*/
ReferenceType type()
default
ReferenceType.CustomTableModel;
/**
* Expressions like "System.Username",String of modelName
*
@return
*/
@SuppressWarnings(
"
rawtypes
"
)
Class model();
}
可能这只是默认java编译器的错误之一(项目中还会有其他的类型不匹配异常)
我解决的办法,是直接使用 Eclipse的JDT 编译器
a.
找到 jdtCompilerAdapter.jar and
org.eclipse.jdt.core_3.5.2.v_981_R35x.jar (search
org.eclipse.jdt.core in eclipse directory)
b. 然后把它们放入
${ANT_HOME}/lib
c.
加入配置<property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/> in builder.xml
2.GWT 的client包,默认会编译到classes目录下,但是发布的时候,是不需要的(一个GWT项目可能会编译出来 1000多个 classes,来自于大量的Handler匿名类)
发布的时候,会超过GAE的限制,所以Deploy前,可以使用Ant 删除之
3.JPA的增强编译配置,Datanucleus 官方的实例是基于JDO的,但是,我们项目是基于 JPA的,配置略有不同
<
path
id
="datanucleus.path"
>
<
pathelement
location
="war/WEB-INF/classes"
/>
<
fileset
dir
="war/WEB-INF/lib"
>
<
include
name
="*.jar"
/>
</
fileset
>
<
fileset
dir
="war/WEB-INF/classes"
>
<
include
name
="com/eyuntong/bespoke/shared/datatypes/BespokeDomain.class"
/>
<
include
name
="com/eyuntong/bespoke/shared/datatypes/BespokeModel.class"
/>
<
include
name
="com/eyuntong/bespoke/shared/datatypes/BespokeTable.class"
/>
<
include
name
="com/eyuntong/bespoke/shared/datatypes/BespokeField.class"
/>
<
include
name
="com/eyuntong/bespoke/shared/datatypes/BespokeType.class"
/>
<
include
name
="com/eyuntong/bespoke/shared/datatypes/RowConstraint.class"
/>
<
include
name
="com/eyuntong/bespoke/shared/datatypes/BackReferences.class"
/>
<
include
name
="com/eyuntong/bespoke/shared/datatypes/BespokeReference.class"
/>
<
include
name
="com/eyuntong/bespoke/shared/datatypes/BespokeOptions.class"
/>
<
include
name
="com/eyuntong/bespoke/shared/datatypes/LangProperties.class"
/>
<
include
name
="com/eyuntong/bespoke/shared/datatypes/LangCodes.class"
/>
<
include
name
="com/eyuntong/bespoke/shared/datatypes/BespokeRowFile.class"
/>
<
include
name
="com/eyuntong/bespoke/server/core/storage/GoogleFile.class"
/>
<
include
name
="com/eyuntong/bespoke/shared/entities/ConditionSetting.class"
/>
</
fileset
>
</
path
>
<!--
Google App Engine Targets
-->
<
target
name
="enhance"
depends
="javac"
description
="Performs enhancement on compiled data classes."
>
<
taskdef
name
="datanucleusenhancer"
classpathref
="datanucleus.path"
classname
="org.datanucleus.enhancer.tools.EnhancerTask"
/>
<
datanucleusenhancer
classpathref
="datanucleus.path"
failonerror
="false"
api
="JPA"
enhancerName
="ASM"
persistenceUnit
="GaeJpa"
>
</
datanucleusenhancer
>
</
target
>
手动指定需要增强编译的 JPA Entities 即可
4.Google App Engine 提供的ant支持 小问题
dev_appserver target有一个问题: 是一旦打开了命令窗口,默认无法停止(从命令行,能够startServer,没法stopServer ,有点诡异
)
GAE 论坛上一位老兄,有一招,我引过来了。
<
macrodef
name
="dev_appserver2"
description
="Runs the App Engine Development App Server"
>
<
attribute
name
="war"
description
="The exploded war directory containing the application"
/>
<
attribute
name
="port"
default
="8080"
description
="The port the server starts on"
/>
<
attribute
name
="address"
default
="localhost"
description
="The interface the server binds to"
/>
<
element
name
="options"
optional
="true"
description
="Additional options for dev_appserver"
/>
<
element
name
="args"
optional
="true"
description
="Additional arguments for the java task"
/>
<
sequential
>
<
java
classname
="com.google.appengine.tools.development.DevAppServerMain"
classpath
="${appengine.tools.classpath}"
fork
="true"
failonerror
="true"
>
<
jvmarg
value
="-Dlog4j.configuration=log4j.props"
/>
<
jvmarg
value
="-javaagent:${appengine.sdk.home}/lib/agent/appengine-agent.jar"
/>
<
arg
value
="--address=@{address}"
/>
<
arg
value
="--port=@{port}"
/>
<
arg
value
="@{war}"
/>
<
args
/>
</
java
>
</
sequential
>
</
macrodef
>
<
target
name
="runserver"
depends
="enhance"
description
="Starts the development server."
>
<
dev_appserver2
war
="war"
port
="80"
/>
</
target
>
最后再 给出完整的 Builder.xml /Files/Herist/build.xml
到此结束,可能以后 再也不会从事 GAE +GWT 项目的开发了,用这个Builder来个总结吧 !