Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Guava 10's Predicate and Function interfaces with GWT 2.4.0

Tags:

java

guava

gwt

Are Predicates and Functions supported in GWT 2.4.0 and Guava GWT 10.0.1? Both interfaces are marked as @GwtCompatible.

When running the project in debug hosted mode, I receive run-time validation errors at the uses of Predicate:

[ERROR] [MyProject] - Line XXY: The import javax.annotation.Nullable cannot be resolved

[ERROR] [MyProject] - Line YYY: Nullable cannot be resolved to a type

From other StackOverflow posts, I believe these errors should not require including JSR 305 in the path as of Guava version 09 (including JSR 305 in the path didn't fix the problem, anyway).

I also appear to receive a couple interface mismatch errors:

[ERROR] [MyProject] - Line XXX: The type new Function(){} must implement the inherited abstract method Function.apply(Object)

[ERROR] [MyProject] - Line YYY: The method apply(MyType) of type new Function(){} must override or implement a supertype method

, and similar errors at uses of Predicate, which I submitted as a bug: http://code.google.com/p/guava-libraries/issues/detail?id=765

Any ideas as to what might be wrong with my setup?

My Project.gwt.xml file contains the following lines:

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

My java file includes the following imports:

import com.google.common.base.Function;
import com.google.common.base.Predicate;

I am using Eclipse 3.7.1 and JavaSE-1.6

like image 810
Todd Schiller Avatar asked Oct 19 '11 06:10

Todd Schiller


1 Answers

I just had the same problem and found a solution to this. The problem is that the JSR 305 sourcecode is not part of a GWT module and therefore ignored by GWT. To fix it do the following:

  • Add a GWT module descriptor to jsr305-2.0.0.jar. Inside the jar which should contain at least the java sources in the subfolder javax/annotation add a file Annotation.gwt.xml with the following content:
<?xml version="1.0" encoding="UTF-8"?>
<module>
    <source path="" />
</module>
  • Add the modified jsr305-2.0.0.jar to your GWT project's classpath in eclipse. Though stated elsewhere it is not requiered to add this jar to WEB-INF/lib

  • Let your project's modules inherit from the newly created GWT module by adding the following line to you modules's .gwt.xml files:

<inherits name='javax.annotation.Annotation'/>

That's it! Now your eclipse project will compile successfully and development/hosted mode will work too.

like image 132
Gandalf Avatar answered Oct 18 '22 17:10

Gandalf