简体   繁体   中英

GWT compile unable to load class

I'm trying to compile GWT from my project from command line (no Ant/Maven) like this

java -cp "/home/user/gwt-2.8.2/*:/home/user/myapp/src:/home/user/myapp/lib/*" com.google.gwt.dev.Compiler com.myapp.webservices.SpwrWebServices

but error is thrown

Loading inherited module 'com.myapp.webservices.SpwrWebServices'
   Loading inherited module 'gwt.material.design.GwtMaterialWithJQuery'
      Loading inherited module 'gwt.material.design.GwtMaterialDesignBase'
         [WARN] Line 40: Setting configuration property named 'CssResource.legacy' in module 'gwt.material.design.GwtMaterialDesignBase' that has not been previously defined
   [ERROR] Line 18: Unable to load class 'com.myapp.webservices.client.util.GitCommitGenerator'
java.lang.ClassNotFoundException: com.myapp.webservices.client.util.GitCommitGenerator
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at com.google.gwt.dev.cfg.ModuleDefSchema$ClassAttrCvt.convertToArg(ModuleDefSchema.java:899)
    at com.google.gwt.dev.util.xml.HandlerArgs.convertToArg(HandlerArgs.java:64)
    at com.google.gwt.dev.util.xml.HandlerMethod.invokeBegin(HandlerMethod.java:221)
    at com.google.gwt.dev.util.xml.ReflectiveParser$Impl.startElement(ReflectiveParser.java:296)
    at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
    at org.apache.xerces.impl.dtd.XMLDTDValidator.startElement(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
    at com.google.gwt.dev.util.xml.ReflectiveParser$Impl.parse(ReflectiveParser.java:349)
    at com.google.gwt.dev.util.xml.ReflectiveParser$Impl.access$200(ReflectiveParser.java:70)
    at com.google.gwt.dev.util.xml.ReflectiveParser.parse(ReflectiveParser.java:431)
    at com.google.gwt.dev.cfg.ModuleDefLoader.nestedLoad(ModuleDefLoader.java:316)
    at com.google.gwt.dev.cfg.ModuleDefLoader.load(ModuleDefLoader.java:243)
    at com.google.gwt.dev.cfg.ModuleDefLoader.doLoadModule(ModuleDefLoader.java:193)
    at com.google.gwt.dev.cfg.ModuleDefLoader.loadFromResources(ModuleDefLoader.java:151)
    at com.google.gwt.dev.cfg.ModuleDefLoader.loadFromClassPath(ModuleDefLoader.java:126)
    at com.google.gwt.dev.Compiler.compile(Compiler.java:139)
    at com.google.gwt.dev.Compiler$1.run(Compiler.java:118)
    at com.google.gwt.dev.CompileTaskRunner.doRun(CompileTaskRunner.java:55)
    at com.google.gwt.dev.CompileTaskRunner.runWithAppropriateLogger(CompileTaskRunner.java:50)
    at com.google.gwt.dev.Compiler.main(Compiler.java:125)

I do have the file src/com/myapp/webservices/client/util/GitCommitGenerator.java so I don't understand my this error is showed. My gwt config xml file looks like this

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.7.0//EN" "\s">
<module rename-to= "SpwrWebServices">
    <inherits name="com.google.gwt.user.User" />

   <!--  GwtMaterialWithJQuery module is smaller and should be  used for production code -->
   <!--   <inherits name="gwt.material.design.GwtMaterialWithJQuery" /> -->

   <!-- GWTMaterialWithJQueryDebug   This module  is larger and includes non-minified source for easier debugging --> 
   <!-- GWT Material -->
    <inherits name="gwt.material.design.GwtMaterialWithJQuery"/>
    <inherits name="gwt.material.design.addins.GwtMaterialAddins"/>
    <inherits name="org.fusesource.restygwt.RestyGWT" />
    <inherits name='com.googlecode.gwt.charts.Charts'/>
    <inherits name="org.moxieapps.gwt.uploader.Uploader"/>
    <set-property name="gwt.logging.enabled" value="TRUE"/>
    <set-property name="gwt.logging.logLevel" value="INFO"/>
    <generate-with class="com.myapp.webservices.client.util.GitCommitGenerator">
        <when-type-assignable class="com.myapp.webservices.client.util.GitCommit"/>
     </generate-with>
  <source path="client" />
  <!--  <source path ="shared" />  -->
    <entry-point
        class="com.myapp.webservices.client.SpwrWsEntryPoint" />
    <set-property name="user.agent" value="gecko1_8,safari"/>
    <set-configuration-property name='xsiframe.failIfScriptTag' value='FALSE'/>
</module>

What is wrong with the configuration above and how can I get a clean compilation?

First, generators should not be written new any more, you should start with Java Annotation Processors or some other feature which does not rely on the GWT compiler generating code.

Second, any Generator you write should not be put in your client package, but should be somewhere that GWT will not try to compile it to JS sources. Usually people use the convention of rebind for the classes which let you change bindings of your GWT code and generate new classes.

Finally, it looks like you are running the GWT compiler on your sources without first compiling them with java. First, use javac to compile all your .java files to .class files, and then pass those on the rest of the classpath. Technically you only need your generator and anything it references, but you'd probably like Javac to report errors before GWT does, since it will do a nicer job.

Consider Maven or Gradle to manage your build instead, so it does the javac work for you, and builds the classpath to give to GWT for you too.

The project defines a generator inside the module descriptor:

    <generate-with class="com.myapp.webservices.client.util.GitCommitGenerator">
        <when-type-assignable class="com.myapp.webservices.client.util.GitCommit"/>
     </generate-with>

The generator is located under the client -package. GWT will try to compile it, which will pretty sure fail.

Try this:

  • create a new package besides the client package, call ist rebind
  • move the GitCommitGenerator to that package.
  • update the reference inside your module descriptor to
     <generate-with class="com.myapp.webservices.rebind.GitCommitGenerator">
        <when-type-assignable class="com.myapp.webservices.client.util.GitCommit"/>
     </generate-with>

Think, this will solve the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM