简体   繁体   English

让Guava参与GWT工作

[英]Getting Guava to work on GWT

I can't get Guava to work with GWT. 我无法让Guava与GWT合作。 I'm using Eclipse, I've added both guava-11.0.2.jar and guava-gwt-11.0.2.jar to my class path, inherited the module com.google.common.collect.Collect in my gwt.xml file but still can't get it working. 我正在使用Eclipse,我已经将guava-11.0.2.jarguava-gwt-11.0.2.jar到我的类路径中,继承了我的gwt.xml com.google.common.collect.Collect模块文件,但仍然无法使其工作。

It compiles but when I run it a lot of error appear. 它会编译,但是当我运行它时会出现很多错误。 Many of them refering to unresolvable annotation javax.annotation.Nullable 其中许多引用了无法解析的注释javax.annotation.Nullable

I tried adding jsr305.jar to my class path but nothing chanded. 我尝试将jsr305.jar添加到我的类路径但没有任何chanded。

Also some errors appear depending on which version of Guava I include (tried with 11.0.2, 11.0.1, 10.0.1) and if I include or not the jsr305.jar 还会出现一些错误,具体取决于我包含的番石榴版本(尝试使用jsr305.jar )以及是否包含jsr305.jar

Some examples of these error are: 这些错误的一些例子是:

  • The type PersonActivity.PersonFilterPredicate must implement the inherited abstract method Predicate<PersonRoleProxy>.apply(Object) PersonActivity.PersonFilterPredicate类型必须实现继承的抽象方法Predicate<PersonRoleProxy>.apply(Object)
  • The method compare(T, T) in the type Ordering<T> is not applicable for the arguments (Object, Object) Ordering<T>类型中的方法compare(T, T)不适用于参数(Object, Object)

Which is quite strange because the code compiles and these kind of error should appear at compile time. 这很奇怪,因为代码编译并且这些错误应该在编译时出现。

We have been embarrassingly unable to figure out the solution to the @Nullable problem, which we believe to be a GWT problem. 我们一直难以找出@Nullable问题的解决方案,我们认为这是一个GWT问题。 You can follow along at http://code.google.com/p/guava-libraries/issues/detail?id=776 We're trying to get help from the GWT team, but things have been kind of crazy lately for the people who work on the part of the compiler we're interested in. It does look like you can work around the problem by removing -strict from your GWT compilation arguments, but of course that's a terrible workaround. 您可以访问http://code.google.com/p/guava-libraries/issues/detail?id=776我们正在努力寻求GWT团队的帮助,但最近有些事情让我感到很疯狂。我们感兴趣的编译器工作的人。看起来你可以通过从GWT编译参数中删除-strict来解决问题,但当然这是一个糟糕的解决方法。

Other users' experiences suggest that the weird other errors you're seeing are related to the @Nullable problem, though I haven't seen definitive confirmation. 其他用户的体验表明,您看到的奇怪的其他错误与@Nullable问题有关,但我还没有看到明确的确认。 You might also confirm that all your imports are com.google.common.* and not com.google.gwt.thirdparty.guava.common.* 您可能还确认所有导入都是com.google.common.*而不是com.google.gwt.thirdparty.guava.common.*

Sorry for all the trouble. 对不起,所有的烦恼。 This is one of a few major thorns in our side at the moment. 这是我们此刻的一些主要荆棘之一。

The following workaround works for GWT 2.4.0 with 以下解决方法适用于GWT 2.4.0

  • Guava 14.0 RC1 and 番石榴14.0 RC1和
  • jsr305-1.3.9.jar jsr305-1.3.9.jar

Create a file named Annotation.gwt.xml with the following content: 使用以下内容创建名为Annotation.gwt.xml的文件:

<module>
  <source path=""/>
</module>

Within the archive jsr305-1.3.9.jar copy this file into sub-directory javax/annotation. 在存档jsr305-1.3.9.jar中将此文件复制到子目录javax / annotation中。

Add the following line to your applications .gwt.xml file: 将以下行添加到应用程序.gwt.xml文件中:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM