How to split code between multiple Eclipse GWT projects?

I would like to have several GWT projects that have common code. Is it possible? AFAICT, my GWT projects need each of them to have its own directory, the source directly below it, which seems to prevent code sharing. I tried to use linked folders, but GWT did not seem to like it (described here ).

If I want to do this, my only choice is to convert the code I want to pass into a .jar file and then inherit it in each of the XML files of my projects? Is there a way to make eclipse do this packing automatically, or do I need some kind of "change-shared-code / compile-jar / use-in-other-project" loop?

Are there any other solutions?

+4
source share
2 answers

I solve this problem with maven. The common code is packaged as a separate maven project and then used as a library. Here are the snippets from the 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 the additional source files needed by the GWT compiler to the last jar.

If you use eclipse as an IDE, the m2eclipse plugin can be used to automatically process all dependencies. It is possible that all projects open in one workspace and the classpath of a common project will be shared. The only drawback is the requirement to call project > clean from time to time (it will force the built-in maven to copy all the resources specified in the above snippet).

+4
source

I think all you have to do is make two separate GWT projects, for example. project A for common code and project B, which uses the code from project A.

When you have these two projects, you need to complete two steps:

  • Add project A to the build path of the project B in Eclipse.
  • Inherit the Gwt.xml project in project B.

Now you can use the hosting mode / compilation in Eclipse.

+1
source

All Articles