How to share code between multiple GWT eclipse projects?

主宰稳场 提交于 2019-12-03 17:02:31

I solve this problem with help of maven. The common code is packaged as separate maven project and then used as library. Here are snippets from pom.xml file:

<dependency>
  <groupId>com.google.gwt</groupId>
  <artifactId>gwt-user</artifactId>
  <version>2.0.4</version>
  <scope>provided</scope>
</dependency>
<dependency>
  <groupId>com.google.gwt</groupId>
  <artifactId>gwt-dev</artifactId>
  <version>2.0.4</version>
  <scope>provided</scope>
</dependency>

<build>
  <resources>
    <resource>
      <directory>src/main/java</directory>
      <includes>
        <include>**/client/**/*.java</include>
        <include>**/client/**/*.properties</include>
        <include>**/shared/**/*.java</include>
        <include>**/shared/**/*.properties</include>
        <include>**/*.gwt.xml</include>
      </includes>
    </resource>
  </resource>
</build>

The above build configuration copies additional source files needed by GWT compiler into final jar.

In case of using eclipse as IDE, the m2eclipse plugin can be used for handling all the dependencies automatically. It is possible to have all the projects opened in single workspace and classpath of the common project will be shared. The only drawback is the requirement of invoking project > clean from time to time (will force embedded maven to copy all the resources specified in the snippet above).

I think all you need to do is make two separate GWT projects, e.g. project A for shared code and project B that uses code from project A.

Once you have these two projects, two steps are required:

  1. Add project A to project B's build path in Eclipse.
  2. Inherit project A's gwt.xml in project B.

You should now be able to use hosted mode / compile within Eclipse.

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