I have a build.xml that work fine, until I start using boilerplate generation and create a Generator.
Everything works fine in Dev Mode, but, I was unable to generate a war for my application.
I think that is because the gen classes are going to /apt_generated
, not /src
, and my ant compiles /src
, I just don't have any idea about generators.
I'm just trying to make it work, but I can't.
Can someone help me?
My build.xml is just like this:
<property name="version" value="1.0.0-SNAPSHOT"/>
<property name="gwt.module.name" value="com.test.Test"/>
<property name="server.resources.name" value="server_resources"/>
<property name="jar.name" value="test${version}.jar"/>
<property name="war.name" value="test${version}.war"/>
<property name="src.dir" location="src"/>
<property name="server.resources.dir" location="war/${server.resources.name}"/>
<property name="build.dir" location="build"/>
<property name="build.server.resources.dir" location="war/WEB-INF/classes/server_resources"/>
<property name="lib.dir" location="war/WEB-INF/lib"/>
<property name="gwt.client.dir" location="com/test/client"/>
<path id="project.classpath">
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
</fileset>
</path>
<target name="prepare">
<mkdir dir="${build.dir}"/>
</target>
<target name="clean">
<delete dir="${build.dir}"/>
</target>
<!-- Compile the java source code using javac -->
<target name="compile" depends="prepare">
<javac srcdir="${src.dir}" destdir="${build.dir}">
<classpath refid="project.classpath"/>
</javac>
</target>
<!-- Invoke the GWT compiler to create the Javascript for us -->
<target name="gwt-compile" depends="compile">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
<classpath>
<!-- src dir is added to ensure the module.xml file(s) are on the classpath -->
<pathelement location="${src.dir}"/>
<pathelement location="${build.dir}"/>
<path refid="project.classpath"/>
</classpath>
<jvmarg value="-Xmx512M"/>
<arg value="${gwt.module.name}"/>
</java>
</target>
<!-- Package the compiled Java source into a JAR file -->
<target name="jar" depends="compile">
<jar jarfile="${lib.dir}/${jar.name}" basedir="${build.dir}/">
<!-- Don't wrap any of the client only code into the JAR -->
<exclude name="${gwt.client.dir}/**/*.class"/>
</jar>
</target>
<!-- Copy the static server resources into the required
directory ready for packaging -->
<target name="copy-resources">
<copy todir="${build.server.resources.dir}" preservelastmodified="true">
<fileset dir="${server.resources.dir}"/>
</copy>
</target>
<!-- Package the JAR file, Javascript, static resources
and external libraries into a WAR file -->
<target name="war" depends="gwt-compile, jar, copy-resources">
<war basedir="war" destfile="${war.name}" webxml="war/WEB-INF/web.xml">
<exclude name="WEB-INF/**" />
<exclude name="${server.resources.name}/**"/>
<webinf dir="war/WEB-INF/">
<include name="classes/${server.resources.name}/**" />
<include name="**/*.jar" />
<!-- <exclude name="**/gwt-dev.jar" /> -->
<exclude name="**/gwt-user.jar" />
</webinf>
</war>
</target>
</project>
The errors:
[javac] D:\CARLOS\workspaces\Test\Test\src\com\test\server\actionhandlers\autenticar\RecuperarSenhaActionHandler.java:50: cannot find symbol
[javac] symbol : class RecuperarSenhaAction
[javac] location: class com.test.server.actionhandlers.autenticar.RecuperarSenhaActionHandler
[javac] public void undo(RecuperarSenhaAction arg0, RecuperarSenhaResult arg1, ExecutionContext arg2) throws ActionException
[javac] D:\CARLOS\workspaces\Test\Test\src\com\test\server\i18n\EnumMessageGenerator.java:84: cannot find symbol
[javac] symbol : class SourceWriter
[javac] location: class com.test.server.i18n.EnumMessageGenerator
[javac] SourceWriter sw = composer.createSourceWriter(context, printWriter);
[javac] ^
[javac] 15 errors
EDIT.
I modify my build.xml, now, I have one more property, <property name="apt_generated.dir" location="apt_generated" />
, and my compile target turns in into this:
<target name="compile" depends="prepare">
<javac destdir="${build.dir}">
<src location="${src.dir}" />
<src location="${apt_generated.dir}" />
<classpath refid="project.classpath" />
</javac>
</target>
That "solve" the issue with apt_generated (I think), but I still can't build it because the errors with SourceWriter and javax.validation classes.
Generated classes need to be compiled too. As i don't see any code generation in your example I just assumed the following values.
<target name="compile" depends="prepare">
<-- compile generated classes-->
<javac srcdir="${apt_generated.dir}" destdir="${build.generated.dir}">
<classpath refid="project.classpath"/>
</javac>
<-- compile sources -->
<javac srcdir="${src.dir}" destdir="${build.dir}">
<classpath location="${build.generated.dir}"/>
<classpath refid="project.classpath"/>
</javac>
</target>
As stated in your comment the generated classes depend on the sources and vice versa, so you need to:
The second could be accomplished like:
<target name="compile" depends="prepare">
<javac destdir="${build.dir}">
<src location="${src.dir}" />
<src location="${apt_generated.dir}" />
<classpath refid="project.classpath" />
</javac>
</target>
If anything else misses make sure that: