Problem compiling a gwt project with ant

I have been using GWT for quite some time and only used the eclipse plugin to compile my projects. Due to the new requirement, I have to use the ant construct (for the first time) to create a gwt project. First I will say that I have 2 modules that have an entry point and 2 other common modules that contain only Java classes (which should be translated into js) and they are sitting in another project in my workspace.

I currently have a GWT project that requires a Common Project, which in turn requires a DAL project (when I say, I want to say that it is so defined in the way of building an eclipse project). In my GWT project, I have the Common.gwt.xml and DAL.gwt.xml files in the appropriate place that define them as modules, and my ModuleEntryPoint.gwt.xml inherits these two modules (in addition to the other modules). When I currently use the gwt eclipse plugin to compile, everything works fine.

However, when I tried to simulate this using the ant assembly, compiling my EnterPoint module fails because the compiler says it cannot find sources for classes belonging to the DAL or Common module.

The ant build code is very simple since this is my first approach.
Thanks in advance for your help.

    <path id="compile.classpath">
    <fileset dir="${build.dir.WEB-INF.lib}">
                <include name="**/*.jar" />
                <include name="**/*.xml" />
    </fileset>
    <fileset dir="${ExternalLib.WebServer.dir}">
            <include name="**/*.jar" />
            <include name="**/*.xml" />
    </fileset>

    <fileset dir="${GWT.dir}">
            <include name="**/*.jar" />
            <include name="**/*.dll" />
    </fileset>

</path>

<target name="clear_previous_war">
<delete dir="${build.dir}" />
<mkdir dir="${build.dir.WEB-INF.classes}"/>
<mkdir dir="${build.dir.WEB-INF.lib}"/>

<target name="build_common" >
    <jar destfile="${build.dir.WEB-INF.lib}/${jar.common}"
        basedir="${common.dir.build}"
        includes="com/**"
        excludes="**/.svn"
      />    
</target>

<target name="build_dal" >
    <jar destfile="${build.dir.WEB-INF.lib}/${jar.dal}"
        basedir="${dal.dir.build}"
        includes="com/**"
        excludes="**/.svn"
      />    
</target>

<target name="copy_additional_files" >
    ... Copies all required external jars to web-inf/lib
</target>

<target name="compile_web_classes" >
    <javac srcdir="src" classpathref="compile.classpath"
    destdir="${build.dir.WEB-INF.classes}"
            source="1.6"/>  
</target>

<target name="compile_gwt_button"  description="GWT compile to JavaScript">
                <java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
                        <classpath>
                                <pathelement location="${src.dir}" />
                                <path refid="compile.classpath" />                  
                        </classpath>
                        <jvmarg value="-Xmx256M" />
                        <arg value="com.myCompany.web.Button" />
                </java>
 </target>

<target name="deploy" description="Build web project">
    <antcall target="clear_previous_war" />
    <antcall target="build_common" />
    <antcall target="build_dal" />
    <antcall target="copy_additional_files" />
    <antcall target="compile_web_classes" />
    <antcall target="compile_gwt_button" />
</target>
+5
source share
2 answers

In the task, compile-gwtI did not give it a path to the sources of the common modules (../Common/src, etc.), so I added it and it works. Sort of:

<classpath>
    <pathelement location="src"/>
    <pathelement location="../Common/src"/>
    <path refid="gwt.compile.classpath"/>
  </classpath>
+4
source

Do something like that

<condition property="gwtCompiler" value="gwt-dev-linux.jar">
    <os family="unix" />
</condition>
<condition property="gwtCompiler" value="gwt-dev-windows.jar">
    <not>
        <os family="unix" />
    </not>
</condition>

<echo>${gwtCompiler}</echo>

<path id="gwt.compile.classpath">
        <pathelement path="${java.class.path}/" />
        <pathelement location="${gwt.sdk.location}/gwt-user.jar" />
.. add here your dependencies
    <pathelement location="${gwt.sdk.location}/${gwtCompiler}" />
        <pathelement location="${gui.source}" />
</path>

<target name="compile-gwt" depends="compile-gui" description="GWT compile to JavaScript">
    <java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
      <classpath>
        <pathelement location="src"/>
        <path refid="gwt.compile.classpath"/>
      </classpath>
      <!-- add jvmarg -Xss16M or similar if you see a StackOverflowError -->
      <jvmarg value="-Xmx256M"/>
      <!-- Additional arguments like -style PRETTY or -logLevel DEBUG -->
      <arg value="${gwt.entrypoint.class}" />
    </java>
  </target>

Where

  • {gwt.sdk.location} is the position in which the GWT JAR packages are located
  • $ {gwtCompiler} - uses the compiler (Linux / Windows)

NOTE : you need to remove javax from gwt-user.jar for deployment. As far as I know, this will be an open issue

0
source

All Articles