Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Guava with GWT

Tags:

guava

gwt

Could someone tell me what I need to do to enable Guava support in GWT.

I have downloaded Guava R07 and in there there are the following two files:

  • guava-r07.jar
  • guava-r07-gwt.jar

I have a few questions regarding this:

  1. Where do these files go? I am guessing that the standard Jar is made available to my IDE for coding, and that both are made available to the GWT compiler for building the JavaScript?
  2. Do I need to add all the .gwt.xml files from the -gwt.jar into my project's main gwt.xml file or only the portions I need?
  3. There are other Jars on the trunk of the Guava&GWT project (ie not in the download, such as one for jsr305) which I think I may need, but I'm not sure.

Sorry, normally I don't have trouble with this kind of thing, but I can't quite work out what goes where.

FYI I'm using GWT 1.6 for the time being, but am hoping to move to 2 soon. If Guava isn't compatible with 1.6 that is not a problem.

Update

I have the following files in a folder called gwtlib:

  • guava-r07-gwt.jar
  • guava-r07.jar
  • jsr305-1.3.9.jar

And my Ant script does the following:

<path id="project.class.path">
    <fileset dir="gwtlibs" includes="guava-r07.jar"/>
    <fileset dir="gwtlibs" includes="guava-r07-gwt.jar"/>
    <fileset dir="gwtlibs" includes="jsr305-1.3.9.jar"/>
    <pathelement location="${gwt.sdk}/gwt-user.jar"/>
    <fileset dir="${gwt.sdk}" includes="gwt-dev*.jar"/>
</path>

<target name="gwtc">
    <java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
        <classpath>
            <pathelement location="app"/>
            <path refid="project.class.path"/>
        </classpath>
        <jvmarg value="-Xmx256M"/>
        <arg value="-localWorkers"/>
        <arg value="2"/>
        <arg value="-war"/>
        <arg value="gwt-public"/>
        <arg value="Main"/>
    </java>
</target>

Running the above command, I get the following errors:

  • Errors in 'jar:file:///project/gwtlibs/guava-r07-gwt.jar!/com/google/common/collect/Constraints.java'
  • Line 254: The method subList(int, int) is undefined for the type List

Without the jsr jar on the classpath, I get the following errors:

  • The import javax.annotation cannot be resolved
  • Nullable cannot be resolved to a type

Thanks

Rich

like image 392
Rich Avatar asked Oct 26 '10 12:10

Rich


2 Answers

  1. Add these jars to your classpath. If you're using IDE, add them to your Build Path by right-clicking "Referenced Libraries" in your Package Exporer, select "Configure Build Path" and add them as external JARs.
  2. You only need to inherit the modules you plan on using in your .gwt.xml file. For example, if you only use the common.collect package, just add <inherits name="com.google.common.collect.Collect" />
  3. You probably don't need jsr305.jar, but if you do, just add it the same way as you added the other jars.

Guava should work just fine with GWT 1.6, if it doesn't then it's probably a bug.

like image 79
Jason Hall Avatar answered Oct 21 '22 03:10

Jason Hall


Guava isn't compatible with GWT 1.6. List.subList, in particular, is added to GWT in GWT 2. The earliest version that we fully supported is GWT 2.0.4

like image 28
Hayward Chan Avatar answered Oct 21 '22 03:10

Hayward Chan