2

I'm trying to use just the Java to Javascript compiler of the GWT from Ant.

Can I use the GWT compiler without extending any Google classes such as com.google.gwt.core.Core or similar. If so how? I'm currently using the setup below on GWT 2.4.0.

I'm calling the ant task:

build.xml

 <target name="gwtc" description="GWT compile to JavaScript (production mode)">
    <java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
      <classpath>
        <pathelement location="src"/>
        <path refid="project.class.path"/>
        <pathelement location="${gwt.sdk}/validation-api-1.0.0.GA.jar" />
        <pathelement location="${gwt.sdk}/validation-api-1.0.0.GA-sources.jar" />
      </classpath>
      <!-- add jvmarg -Xss16M or similar if you see a StackOverflowError -->
      <jvmarg value="-Xmx256M"/>
      <arg line="-war"/>
      <arg value="war"/>
      <!-- Additional arguments like -style PRETTY or -logLevel DEBUG -->
      <arg line="${gwt.args}"/>
      <arg value="foo.Test1"/>
    </java>
  </target>

foo/Test.java

package foo;

public class Test1 {
    public String field1;
    public String field2;
    public int field3;

}

foot/Test1.gwt.xml

<module rename-to="hello">
    <source path="foo.Test1"/>
    <!--entry-point class="foo.Test1"/-->
</module>

And output:

gwtc:
     [java] Compiling module foo.Test1
     [java]    [ERROR] Unable to find type 'java.lang.Object'
     [java]       [ERROR] Hint: Check that your module inherits 'com.google.gwt.core.Core' either directly or indirectly (most often by inheriting module 'com.google.gwt.user.User')
Behrang
  • 46,888
  • 25
  • 118
  • 160

1 Answers1

1

The error indicates that you need to inherit 'com.google.gwt.core.Core' in your gwt.xml file and it is not saying that your class should extend/implement it. Give this a try:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE 
    module 
    PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.3.0//EN" 
    "http://google-web-toolkit.googlecode.com/svn/tags/2.3.0/distro-source/core/src/gwt-module.dtd">

<module rename-to="hello">
    <inherits name="com.google.gwt.core.Core" />
    <source path="foo" />
</module>

Or is it that you don't want your module to inherit it?

Behrang
  • 46,888
  • 25
  • 118
  • 160
  • 1
    I had to include an entry-point point but this put me on the right track, thanks. – James Adams Sep 20 '11 at 21:04
  • Do you know I can make public methods from the Test1 class available in the generated Javascript? – James Adams Sep 26 '11 at 10:08
  • As far as I know the GWT compiler detects unused code/methods and prunes them in the generated JavaScript code. I am not sure how one can disable pruning. By the way, if you only want a toolkit for converting Java classes to JavaScript, have a look at DWR (Direct Web Remoting). – Behrang Sep 26 '11 at 11:40
  • Thanks, I'll try and find how to disable this. We already use DWR but it doesn't convert Java to Javascript instead it makes remote Java objects accessible from Javascript via a Javascript stub and behind the scenes AJAX call. – James Adams Sep 26 '11 at 15:45