guava, gwt and eclipse

匿名 (未验证) 提交于 2019-12-03 10:10:24

问题:

Is it possible to use guava in the client side code of a gwt web application? If so, how does one add guava to an Eclipse project?

I've added both the guava-10.0.1 and guava-gwt-10.0.1 jars to my build path and have added the source attachments to each but I still get this error:

No source code is available for type com.google.gwt.thirdparty.guava.common.base.Predicate; did you forget to inherit a required module

回答1:

OK, look at your import line. Does it look like this?

import com.google.gwt.thirdparty.guava.common.base.Predicate; 

That's wrong. Change it to:

import com.google.common.base.Predicate; 

If you use completion assist in Eclipse -- Control-Spacebar -- study the list of offered completions. Don't just pick the first one. Look to the right where it will identify the source of the completion in light grey text. If you are looking at the thirdparty.guava one, move to the next one until you see the google.common one.

Maybe someone can give some insight into what the thirdparty.guava library is used for, whether it needs to be in the build path, and in what order Guava libraries ought to appear in the typical GWT project.



回答2:

Guava classes that are GWT compatible are (supposed to be) marked with the @GwtCompatible annotation. Check the source.

According to this, it is: http://guava-libraries.googlecode.com/svn/trunk/javadoc/com/google/common/base/Predicate.html

You'll still need to follow Thomas Broyer's instructions to put the correct into the .gwt.xml file.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!