Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Google Common Collection in GWT

Tags:

java

guava

gwt

This is a simple problem, but I'm having problems with it...

I'm trying to use Google common collection's Objects.equal() method in a GWT client code, but I'm keep getting the error

20:12:10.001 [ERROR] [gwt_regex] Line 39: No source code is available for type com.google.common.base.Objects; did you forget to inherit a required module?

Tried to Google for the answer, but couldn't find any answer regarding this - everyone just said "Google collection should work off the box with GWT".

like image 510
Jeeyoung Kim Avatar asked Mar 08 '10 04:03

Jeeyoung Kim


3 Answers

You need to inherit the module file:

<inherits name='com.google.common.Collect.gwt.xml' />

and add the source files of both collections and additional gwt specific files. The first are in the zip file from the project page, the latter are available in the gwt folder in collections project trunk: http://code.google.com/p/google-collections/source/browse/#svn/trunk/gwt

like image 109
Hilbrand Bouwkamp Avatar answered Nov 16 '22 08:11

Hilbrand Bouwkamp


To solve your error (No source code is available for type com.google.common.base.Objects), you just need to include Base GWT module :

<inherits name="com.google.common.base.Base" />

If you want to use classes related to collections, you need to include Collect GWT module :

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

PS : tested with GUAVA GWT 17.0

like image 32
Stéphane B. Avatar answered Nov 16 '22 07:11

Stéphane B.


Hilbrand's answer didn't quite work (it gave me bunch of errors when Google collection classes were loaded), and I found another solution.

  1. Check out google collection - http://google-collections.googlecode.com/svn/trunk/
  2. Run the ant target "jargwt"
  3. Add the built jar file "google-collect-gwt-snapshot.jar" to your application's classpath.
  4. Add in your GWT application's module.

The reason Hilbrand's solution didn't work was because Google collection contains alot of gwt-incompaitable java files, and the Collect.gwt.xml module file selects ALL java file under Google Collection.

like image 2
Jeeyoung Kim Avatar answered Nov 16 '22 08:11

Jeeyoung Kim