1

I can run the Java version of my project fine by simply importing Guava libraries like so:

import com.google.gwt.thirdparty.guava.common.collect.ImmutableList;

Following the advice here, I've added this line to html/pom.xml:

<dependency>
  <groupId>com.google.guava</groupId>
  <artifactId>guava-gwt</artifactId>
  <version>10.0.1</version>
</dependency>

And this line to html/project.gwt.xml file:

<inherits name="com.google.common.collect.Collect"/>

But when I try to GWT-Compile my HTML version in Eclipse, I get errors like the following:

[ERROR] Line 61: No source code is available for type com.google.gwt.thirdparty.guava.common.collect.ImmutableList<E>; did you forget to inherit a required module?
klenwell
  • 6,978
  • 4
  • 45
  • 84
  • I did see [this post](http://stackoverflow.com/questions/7794014/guava-gwt-and-eclipse) about changing the classpath to com.google.common.base. Gave this a try but only seemed to make things worse. – klenwell Apr 03 '12 at 05:48
  • I think it should be `com.google.common.collect` in your case. – Etienne Neveu Apr 03 '12 at 07:07

2 Answers2

3

I think you may be importing the wrong class. Try replacing the com.google.gwt.thirdparty.guava.common.collect.ImmutableList import with com.google.common.collect.ImmutableList.

Here is a similar question about the Lists class: Trouble with GWT and Guava

Community
  • 1
  • 1
Etienne Neveu
  • 12,604
  • 9
  • 36
  • 59
  • So I would then need to change all my import statements from `import com.google.gwt.thirdparty.guava.common.collect.Foo;` to `com.google.common.collect.Foo;`? – klenwell Apr 03 '12 at 13:33
  • 1
    I agree that that's what you ought to do. – Louis Wasserman Apr 03 '12 at 14:33
  • 1
    Yes, you were never supposed to be able to import that gwt.thirdparty thing at all. That's GWT's internal copy of ancient versions of our code. – Kevin Bourrillion Apr 03 '12 at 15:44
  • 1
    Part of the problem I'm having is that com.google.gwt.thirdparty.guava.common.collect is the path that Eclipse seems to prefer for some reason. – klenwell Apr 04 '12 at 03:33
  • I use IDEA now, but I seem to remember that Eclipse lets you configure your "favorite" imports, and specify which imports should be proposed by default for auto-completion? – Etienne Neveu Apr 04 '12 at 10:22
  • 1
    Java | Appearance | Type Filters com.google.gwt.thirdparty.* – Chris Povirk Apr 04 '12 at 15:41
2

I selected @eneveu's answer as it got me headed in the right direction. Here are more explicit instructions for enabling Guava in the HTML version of your PlayN project.

1. Add dependency to YourGame-core/pom.xml

<dependency>
  <groupId>com.google.guava</groupId>
  <artifactId>guava-gwt</artifactId>
  <version>11.0.2</version>
</dependency>

2. Right-click YourGame-core directory in Package Explorer window, then: Maven > Update Dependencies

3. For HTML5, add this line to YourGame-html/YourGame.gwt.xml:

 <inherits name="com.google.common.collect.Collect"/> 

4. When importing, use the correct library path:

import com.google.common.collect.Foo;
/* NOT: import com.google.gwt.thirdparty.guava.common.collect.Foo; */

I compiled the code at the link below and tested in Chrome to verify that Guava gets imported successfully:

Community
  • 1
  • 1
klenwell
  • 6,978
  • 4
  • 45
  • 84