如何在多个GWT eclipse项目之间共享代码? [英] How to share code between multiple GWT eclipse projects?

查看:183
本文介绍了如何在多个GWT eclipse项目之间共享代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要有多个共享通用代码的GWT项目。这可能吗? AFAICT我的GWT项目需要每个都有自己的目录,源代码直接在下面,这似乎排除了代码共享。我尝试使用链接的文件夹,但GWT似乎并不喜欢(描述这里)。



如果我想这样做,我唯一的选择是将我要共享的代码转换为.jar文件,然后在我的每个项目的XML文件中继承?有没有办法使eclipse自动执行这个打包,还是需要某种变更共享代码/编译jar /使用其他项目循环?



有没有其他解决方案?

解决方案

我在maven的帮助下解决了这个问题。通用代码打包为单独的maven项目,然后用作库。这是pom.xml文件的片段:

 < dependency> 
< groupId> com.google.gwt< / groupId>
< artifactId> gwt-user< / artifactId>
< version> 2.0.4< / version>
< scope>已提供< / scope>
< / dependency>
<依赖关系>
< groupId> com.google.gwt< / groupId>
< artifactId> gwt-dev< / artifactId>
< version> 2.0.4< / version>
< scope>已提供< / 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>

上述构建配置将GWT编译器所需的其他源文件复制到最终的jar。



如果使用eclipse作为IDE, m2eclipse 插件可以是用于自动处理所有依赖项。可以在单个工作区中打开所有项目,并共享公共项目的类路径。唯一的缺点是需要调用 project>清除(将强制嵌入的maven复制上面的代码片段中指定的所有资源)。


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 underneath, 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).

这篇关于如何在多个GWT eclipse项目之间共享代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆