In PlayN, how can I get the HTML version of my project using Google's Guava libraries to compile?

╄→尐↘猪︶ㄣ 提交于 2019-12-24 10:52:09

问题


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?

回答1:


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




回答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:

  • PlaynDev.java


来源:https://stackoverflow.com/questions/9987720/in-playn-how-can-i-get-the-html-version-of-my-project-using-googles-guava-libr

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