开发者

How to share code between multiple GWT eclipse projects?

I would like to have multiple GWT projects that share common code. Is this possible? AFAICT my GWT projects need to each have their own directory, with source directly unde开发者_如何学运维rneath, which seems to preclude code-sharing. I tried using linked folders, but GWT didn't seem to like that (described here).

If I want to do this, is my only choice to turn the code I want to share into a .jar file, and then inherit that in each of my projects' XML files? Is there a way to make eclipse automatically do this packaging, or would I need some sort of 'change-shared-code/compile-jar/use-in-other-project' loop?

Are there any other solutions?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜