2

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.

1 Answer 1

2

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:

  • EITHER split your project, so that all common dependencies are in another project
  • OR compile everything together

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:

  • the appropriate lib is included in project.classpath (if you are not sure which jar you are missing you can try http://www.findjar.com
  • all sources are on either of one src dir
5
  • 1
    i understand, the problem is that my generated classes use a lot of classes from my normal source, and my normal source use the classes from apt_generated. Sounds like a cross-dependence issue. what do you think?
    – caarlos0
    Dec 14, 2011 at 10:41
  • 1
    @caarlos0 yeah, that is a problem, can you put the generated classes into the src folder? Then you can compile everything at once. Javac can only have on dir, but if all classes are in one src-dir, you won't have any problem.
    – oers
    Dec 14, 2011 at 10:50
  • I was able to "solve" the issue with apt_generate (I edited the question), but, I still getting errors with SourceWriter, javax.validation.* and others... any idea?
    – caarlos0
    Dec 14, 2011 at 13:12
  • 1
    @caarlos0 it is hard to tell, make sure that the missing .java files are in src dir or in one of the libs in your lib.dir
    – oers
    Dec 14, 2011 at 14:57
  • all the libs are in WEB-INF/lib, and i put them all in the classpath for compile... the classes are right too...
    – caarlos0
    Dec 14, 2011 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.