1

I need to compile a GWT project from Java App. So i created a Compiler instance with CompilerOptions which sets output directories etc.

My code is like this:

 Compiler compiler=new Compiler(new CompilerOptions() {......
....
}

   ModuleDef def=new ModuleDef("sampleweb");
            def.clear();
            def.addSourcePackage("D:\\projects\\sampleweb\\src\\com\\sample\\web", new String[]{"client"}, new String[]{}, new String[]{}, true, false);
            def.addGwtXmlFile(new File("D:\\projects\\sampleweb\\src\\com\\sampleweb\\web\\Sampleweb.gwt.xml"));
            TreeLogger logger=new SwingTreeLogger(new SwingLoggerPanel(Type.ALL, new File("x.txt")));
            compiler.run(logger,def);

When the compiler.run is called, a NullPointerException as shown is thrown

Exception in thread "main" java.lang.NullPointerException
    at com.google.gwt.dev.cfg.ModuleDef.getCompilationState(ModuleDef.java:373)
    at com.google.gwt.dev.Precompile.precompile(Precompile.java:246)
    at com.google.gwt.dev.Precompile.precompile(Precompile.java:229)
    at com.google.gwt.dev.Precompile.precompile(Precompile.java:141)
    at com.google.gwt.dev.Compiler.run(Compiler.java:232)
    at com.asklepian.TestApp.Starter.main(Starter.java:400)

How should I configure compiler?

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
Abin Manathoor Devasia
  • 1,945
  • 2
  • 21
  • 47
  • 2
    Do you really need to create a `ModuleDef` from scratch? Have you looked at `ModuleDefLoader`? BTW, `Compiler` loads everything from the classpath, which must be a `URLClasspath` (GWT will _scan_ the classpath) – Thomas Broyer Mar 11 '13 at 15:11
  • +1 . Guessing your are writing a UI tool for GWT Compilation with Swing. Any reason Console, eclipse and IntelliJ are not sufficient? – appbootup Mar 11 '13 at 15:30
  • @ThomasBroyer ya.. i need to create a custom Ui Widgets as per user requirements and need to compile it for generate corresponding JS for the developed widgets.The User will create widgets as like the same Java code, like we write – Abin Manathoor Devasia Mar 11 '13 at 17:43
  • @SSR for the above explained situation i cant do it with IDE – Abin Manathoor Devasia Mar 11 '13 at 17:45
  • 1
    @Abin: that doesn't answer the question: you're adding as source package the `client` subfolder of the same path you're loading a `gwt.xml` from; can't you just load that `SampleWeb.gwt.xml` using `ModuleDefLoader`? or even simpler, use the `run(TreeLogger)` method of the `Compiler` rather than `run(TreeLogger, ModuleDef)`? I'm successfully using `run(TreeLogger)` FWIW. – Thomas Broyer Mar 11 '13 at 17:56
  • @ThomasBroyer thanks it helped me a lot.But when i compile this the exicution possed at one loaction after the log `Computing all possible rebind results for 'com.google.gwt.core.client.impl.StackTraceCreator.Collector'` .What was it actualy doing?. – Abin Manathoor Devasia Mar 12 '13 at 10:54
  • See https://github.com/tbroyer/gwt-maven-plugin/blob/master/src/main/java/net/ltgt/gwt/maven/CompileMojo.java#L335 for my code. HTH – Thomas Broyer Mar 12 '13 at 11:03

1 Answers1

0

I would create just the Java source code and the XML module code, and than execute a Java process who calls the GWT compiler. The GWT compiler is located at com.google.gwt.dev.Compiler, and you can execute it in Windows from the DOS command shell with the java command. The only parameter the compiler needs is the GWT module Location (the location of the module xml file).

  • This is going to be the only real option, since the Compiler calls `System.exit` in several places. This is done to close out any errant threads, rather than let them keep going. – Colin Alworth Mar 11 '13 at 17:32
  • 2
    AFAICT, `System.exit` is only called from `main()`. I successfully call the compiler directly in a Maven mojo. – Thomas Broyer Mar 11 '13 at 17:52