Ant gwt compiler task not running

I am following this tutorial to create an ant build file that java compiles than GWT compiles than doing the correct steps to build my .war file.

I am using Eclipse and GWT compilation works and when I start development mode it works. I have also successfully deployed to tomcat.

The thing is, I run my script, the compiler works, but it doesn't work in the gwt compiler task. My ant build script looks like this:

<project name="vlp" default="gwt.compile" basedir=".">
    <tstamp />
    <!-- ################# PROPERTIES ################ -->
    <!-- directory properties -->
    <!-- source -->
    <property name="projectName" value="VirtualLabPortal" />
    <property name="src.dir" location="src" />
    <property name="build.dir" location="bin" />
    <property name="src.build.dir" location="${build.dir}/src" />
    <property name="gwt.build.dir" location="${build.dir}/gwt" />
    <property name="gwt.unitCache.dir" location="gwt-unitCache" />
    <!-- libraries -->
    <property name="src.lib.dir" location="war/WEB-INF/lib" />

    <!-- ___________________________________________________________________
        |                                                                   |
        |               Configure path source/test                          |
        |___________________________________________________________________| 
    -->
    <path id="compile.path">
        <fileset dir="${src.lib.dir}" includes="*.jar" />
        <fileset dir="${src.lib.dir}/gwt" includes="*.jar" />
    </path>
    <!-- ___________________________________________________________________
        |                                                                   |
        |               Clean old compiled source/test/war                  |
        |___________________________________________________________________| 
    -->
    <target name="clean" description="Clean all the old build files.">
        <delete dir="${build.dir}" />
        <delete dir="${gwt.unitCache.dir}" />
        <delete file="${projectWar}" />
        <delete file="${src.lib.dir}/${projectJar}" />
    </target>
    <!-- ___________________________________________________________________
        |                                                                   |
        |                       Compile the source                          |
        |(should exclude gwtview code which is compiled by the gwt compiler)|   
        |___________________________________________________________________| 
    -->
    <target name="src.compile" depends="clean" description="Compile the source code when everything has been cleaned.">
        <mkdir dir="${src.build.dir}" />
        <javac encoding="utf-8" destdir="${src.build.dir}" nowarn="true">
            <src path="${src.dir}" />
            <classpath refid="compile.path" />
        </javac>
    </target>
    <!-- ___________________________________________________________________
        |                                                                   |
        |                       Invoke the GWT compiler                     |
        |___________________________________________________________________| 
    -->
    <property name="module.gwt.xml" location="${src.dir}/com/banctecmtl/ca/vlp" />
    <target name="gwt.compile" depends="src.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="${module.gwt.xml}" />
                <path refid="compile.path" />
            </classpath>
            <jvmarg value="-Xmx512m" />
            <arg line="${projectName} -logLevel ALL -style OBF -war ${build.dir}" />
        </java>
    </target>
    <!-- ___________________________________________________________________
        |                                                                   |
        |           Copy the config files in the war directory              |
        |___________________________________________________________________| 
    -->
    <property name="config.dir" location="war/config" />
    <target name="copy-resources">
        <copy todir="war/config" preservelastmodified="true">
            <fileset dir="${config.dir}">
                <include name="**.*" />
            </fileset>
        </copy>
    </target>
    <!-- ___________________________________________________________________
        |                                                                   |
        |           Create a Jar to be included in the war                  |
        |___________________________________________________________________| 
    -->
    <property name="projectJar" value="${projectName}.jar" />
    <property name="gwt.client.dir" location="com/banctecmtl/ca/vlp/view/webview" />
    <target name="jar" depends="src.compile">
        <!-- should also depend on gwt.compile -->
        <jar jarfile="${src.lib.dir}/${projectJar}" basedir="${src.build.dir}/">
            <!-- Don't wrap any of the client only code into the JAR
                <exclude name="${gwt.client.dir}/**/*.class"/> -->
            <exclude name="${gwt.client.dir}/**/*.class" />
        </jar>
    </target>
    <!-- ___________________________________________________________________
        |                                                                   |
        |                   Create a War from the source                    |
        |___________________________________________________________________| 
    -->
    <property name="projectWar" value="${projectName}.war" />
    <target name="war" depends="jar,copy-resources">
        <war basedir="war" destfile="${projectWar}" webxml="war/WEB-INF/web.xml">
            <exclude name="WEB-INF/**" />
            <webinf dir="war/WEB-INF/">
                <include name="lib/*.jar" />
                <include name="classes/*.properties" />
                <exclude name="**/gwt-dev.jar" />
                <exclude name="**/gwt-user.jar" />
            </webinf>
        </war>
    </target>

    <!-- ___________________________________________________________________
        |                                                                   |
        |                   Deploy to the production server                 |
        |___________________________________________________________________| 
    -->
    <!-- It is possible you can't run this from eclipse,
     you need to edit the run configurations and add the 
     latest jsch library to the classpath -->
    <property name="user" value="root" />
    <property name="password" value="Banctec01" />
    <property name="prodHost" value="vlp" />
    <property name="dest" value="/usr/share/tomcat6/webapps/ROOT.war" />
    <target name="deploy" depends="war">
        <echo message="Copying to : ${user}@${prodHost}:${dest}" />
        <scp file="${projectWar}" remoteTofile="${user}@${prodHost}:${dest}" password="${password}" trust="true" />
    </target>
</project>

      

The following error failed:

Buildfile: D:\workspace\vlp\build.xml
clean:
   [delete] Deleting directory D:\workspace\vlp\war\WEB-INF\classes
src.compile:
    [mkdir] Created dir: D:\workspace\vlp\war\WEB-INF\classes
    [javac] D:\workspace\vlp\build.xml:42: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
    [javac] Compiling 134 source files to D:\workspace\vlp\war\WEB-INF\classes
    [javac] Note: D:\workspace\vlp\src\com\banctecmtl\ca\vlp\controller\schedule\ScheduledTaskManager.java uses unchecked or unsafe operations.
    [javac] Note: Recompile with -Xlint:unchecked for details.
gwt.compile:
     [java] Checking for updates
     [java]    First launch was 134c3e23387
     [java]    Last ping was Mon Apr 23 14:42:48 EDT 2012, min wait is 86400000ms
     [java] Module location: file:/D:/workspace/vlp/src/com/banctecmtl/ca/vlp/VirtualLabPortal.gwt.xml
     [java] Loading inherited module 'com.google.gwt.user.User'
     [java]    Module location: jar:file:/D:/workspace/vlp/war/WEB-INF/lib/gwt/gwt-user.jar!/com/google/gwt/user/User.gwt.xml
     [java]    Loading inherited module 'com.google.gwt.animation.Animation'
     [java]       Module location: jar:file:/D:/workspace/vlp/war/WEB-INF/lib/gwt/gwt-user.jar!/com/google/gwt/animation/Animation.gwt.xml
     [java]       Loading inherited module 'com.google.gwt.core.Core'
     [java]          Module location: jar:file:/D:/workspace/vlp/war/WEB-INF/lib/gwt/gwt-user.jar!/com/google/gwt/core/Core.gwt.xml
     [java]          Loading inherited module 'com.google.gwt.dev.jjs.intrinsic.Intrinsic'
     [java]             Module location: jar:file:/D:/workspace/vlp/war/WEB-INF/lib/gwt/gwt-dev.jar!/com/google/gwt/dev/jjs/intrinsic/Intrinsic.gwt.xml
     [java]             Loading inherited module 'com.google.gwt.lang.LongLib'
     [java]                Module location: jar:file:/D:/workspace/vlp/war/WEB-INF/lib/gwt/gwt-dev.jar!/com/google/gwt/lang/LongLib.gwt.xml
     [java]          Loading inherited module 'com.google.gwt.emul.Emulation'
     [java]             Module location: jar:file:/D:/workspace/vlp/war/WEB-INF/lib/gwt/gwt-user.jar!/com/google/gwt/emul/Emulation.gwt.xml
     [java]             Loading inherited module 'com.google.gwt.logging.LogImpl'
     [java]                Module location: jar:file:/D:/workspace/vlp/war/WEB-INF/lib/gwt/gwt-user.jar!/com/google/gwt/logging/LogImpl.gwt.xml
     [java]          Loading inherited module 'com.google.gwt.xhr.XMLHttpRequest'
     [java]             Module location: jar:file:/D:/workspace/vlp/war/WEB-INF/lib/gwt/gwt-user.jar!/com/google/gwt/xhr/XMLHttpRequest.gwt.xml
     [java]             Loading inherited module 'com.google.gwt.core.Core'
     [java]                Module 'com.google.gwt.core.Core' has already been loaded and will be skipped
     [java]          Loading inherited module 'com.google.gwt.core.CompilerParameters'
     [java]             Module location: jar:file:/D:/workspace/vlp/war/WEB-INF/lib/gwt/gwt-user.jar!/com/google/gwt/core/CompilerParameters.gwt.xml
     [java]          [...]
     [java]    Loading inherited module 'com.google.gwt.user.User'
     [java]       Module 'com.google.gwt.user.User' has already been loaded and will be skipped
     [java] Public resources found in...
     [java] Translatable source found in...
     [java] Persistent unit cache dir set to: D:\workspace\vlp\war\..\gwt-unitCache
     [java] Compiling module VirtualLabPortal
     [java] Looking for previously cached Compilation Units in D:\workspace\vlp\war\..\gwt-unitCache
     [java] Loaded 0 units from persistent store.
     [java] Starting UnitWriteThread.
     [java]    Found 0 cached units.  Used 0 / 2413 units from cache.
     [java] [ERROR] Unexpected internal compiler error
     [java] java.lang.RuntimeException: Exception processing units
     [java]     at com.google.gwt.dev.javac.CompilationStateBuilder$CompileMoreLater.compile(CompilationStateBuilder.java:248)
     [java]     at com.google.gwt.dev.javac.CompilationStateBuilder.doBuildFrom(CompilationStateBuilder.java:447)
     [java]     at com.google.gwt.dev.javac.CompilationStateBuilder.buildFrom(CompilationStateBuilder.java:370)
     [java]     at com.google.gwt.dev.cfg.ModuleDef.getCompilationState(ModuleDef.java:360)
     [java]     at com.google.gwt.dev.Precompile.precompile(Precompile.java:252)
     [java]     at com.google.gwt.dev.Precompile.precompile(Precompile.java:233)
     [java]     at com.google.gwt.dev.Precompile.precompile(Precompile.java:145)
     [java]     at com.google.gwt.dev.Compiler.run(Compiler.java:232)
     [java]     at com.google.gwt.dev.Compiler.run(Compiler.java:198)
     [java]     at com.google.gwt.dev.Compiler$1.run(Compiler.java:170)
     [java]     at com.google.gwt.dev.CompileTaskRunner.doRun(CompileTaskRunner.java:88)
     [java]     at com.google.gwt.dev.CompileTaskRunner.runWithAppropriateLogger(CompileTaskRunner.java:82)
     [java]     at com.google.gwt.dev.Compiler.main(Compiler.java:177)
     [java] Caused by: java.lang.NoSuchMethodError: com.google.gwt.dev.jjs.ast.JProgram.serializeTypes(Ljava/util/List;Ljava/io/ObjectOutputStream;)V
     [java]     at com.google.gwt.dev.javac.CompilationUnitImpl.<init>(CompilationUnitImpl.java:68)
     [java]     at com.google.gwt.dev.javac.SourceFileCompilationUnit.<init>(SourceFileCompilationUnit.java:48)
     [java]     at com.google.gwt.dev.javac.CompilationUnitBuilder$ResourceCompilationUnitBuilder.makeUnit(CompilationUnitBuilder.java:154)
     [java]     at com.google.gwt.dev.javac.CompilationUnitBuilder.build(CompilationUnitBuilder.java:266)
     [java]     at com.google.gwt.dev.javac.CompilationStateBuilder$CompileMoreLater$1.run(CompilationStateBuilder.java:223)

BUILD FAILED
D:\workspace\vlp\build.xml:60: Java returned: 1

Total time: 36 seconds

      

I found that changing the gwt compiler class name to DevMode succeeds. Usage: classname="com.google.gwt.dev.DevMode"

instead of classname="com.google.gwt.dev.Compiler"

.

EDIT: I've refactored the XML above. The build.xml file cleans up the entire bin directory. I also point out javac

to the directory bin/src

and the compiler on the Google Web Toolkit: bin/gwt

. The compiler still doesn't work ...

EDIT: I downloaded the latest SDK directly from google developers site and overridden the old librairies found in my classpath and in my eclipse plugin. Still won't work with the ant build script.

Does anyone see what might be the problem here?

+3


source to share


4 answers


All I can say is that the method com.google.gwt.dev.jjs.ast.JProgram.serializeTypes(Ljava/util/List;Ljava/io/ObjectOutputStream;)V

is only introduced in gwt-dev 2.4.0 . It does not exist in gwt-dev 2.3.0 .

This means there are two versions of gwt-dev in the classpath. One of them is 2.4.0, so com.google.gwt.dev.javac.CompilationUnitImpl

looking for this method. The other is 2.3.0 or older, so this method was not found (the class JProgram

was loaded by the compiler using an older version).



Try to study them carefully. Or try starting a new environment where you keep a good eye on what comes in.

+3


source


tl; dr: this is due to differences in the linkers provided by Compiler

versus DevMode

in cases of insufficient or incorrect class context

Tracking the problem

I noticed that the reproduction that exists on the current GWT trunk . In particular, it doesn't work in this block of code:

ArrayList<CompilationUnit> resultUnits = new ArrayList<CompilationUnit>();
      do {
        // Compile anything that needs to be compiled.
        buildQueue = new LinkedBlockingQueue<CompilationUnitBuilder>();
        final ArrayList<CompilationUnit> newlyBuiltUnits = new ArrayList<CompilationUnit>();
        final CompilationUnitBuilder sentinel = CompilationUnitBuilder.create((GeneratedUnit) null);
        final Throwable[] workerException = new Throwable[1];
        Thread buildThread = new Thread() {
          @Override
          public void run() {
            try {
              do {
                CompilationUnitBuilder builder = buildQueue.take();
                if (builder == sentinel) {
                  return;
                }
                // Expensive, must serialize GWT AST types to bytes.
                CompilationUnit unit = builder.build(); // <-- Right here.
                newlyBuiltUnits.add(unit);
              } while (true);
            } catch (Throwable e) {
              workerException[0] = e;
            }
          }
        };

      

As we unwind the stack further than your trace, we bounce through the factory and ten layers of code until we finally hit UnifyAst.java . And, here and there:

...
mapApi(enclosingType);

// Now the method should be there.
method = methodMap.get(sig);
if (method == null) {
  // TODO: error logging
  throw new NoSuchMethodError(sig);
}
assert !method.isExternal();
return method;
...

      

This is the only instance NoSuchMethodError

called during the pre-compilation phase of GWT.

Differences in compiler layout and DevMode



Cool. Now that we've dived deep into why this explodes, let's understand why it DevMode

works when Compiler

it doesn't. We note that both import the same copy of Util.java , so technically both types are available statically to our Java compiler (not the GWT compiler).

Checking the linkers, note that it Compiler

uses Link.link

:

Link.link(logger.branch(TreeLogger.TRACE, logMessage), module,
          generatedArtifacts, allPerms, resultFiles, options.getWarDir(),
          options.getDeployDir(), options.getExtraDir(), precompileOptions); 

      

Whereas it DevMode

uses a multipart static call with a separate pass populating the instance StandardLinkerContext

:

link(loadLogger, module);

...

@Override
protected synchronized void produceOutput(TreeLogger logger, StandardLinkerContext linkerStack,
      ArtifactSet artifacts, ModuleDef module, boolean isRelink) throws UnableToCompleteException {

    ...
    linkerStack.produceOutput(linkLogger, artifacts, Visibility.Public, outFileSet);
    linkerStack.produceOutput(linkLogger, artifacts, Visibility.Deploy, deployFileSet);
    linkerStack.produceOutput(linkLogger, artifacts, Visibility.Private, extraFileSet);
    ...
}

      

Fine! So how do I fix it?

As is customary in the middle of writing this post, yair provides one such diagnosis for the problem, noting that the pre-compilation step is not resistant to conflicting class IDs in the context of the two versions of GWT. Other class visibility issues in which precompilation.getGeneratedArtifacts();

incorrect or insufficient objects are pulled in can also cause this replay.

I am guessing the issue is now resolved as yair has received an approved response status. But for other people who work in this post, it is possible that other class or visibility issues could lead to a repetition of this exact problem.

+2


source


The java.io.ObjectOutputStream class is not supported by the GWT compiler.
You should refer to https://developers.google.com/web-toolkit/doc/latest/RefJreEmulation#Package_java_io before using Java classes to make sure GWT supports it.

0


source


You start the JVM to run the Gwt compiler and the directory bin

is in ClassPath.

Since Eclipse is compiled in development mode, the leftover class in the bin

may prevent the compiler from correctly processing some source files.

Make sure the bin directory is empty before invoking the Ant target. Then he can get through.

I recommend that you use two target directories, one for classes compiled from Java sources and another for GWT-generated files. Then the target war

will collect both in WAR.

0


source







All Articles