将GWT项目转变为多模块项目

时间:2016-01-21 16:05:09

标签: java maven gwt jar maven-module

我正在尝试将一个有效的GWT项目转换为几个Maven模块。 新结构应如下所示:

Project
|- pom.xml
|- Project-Common(only Common-Classes)
|--- pom.xml
|--- Packaging: jar
|- Project-War(includes *gwt.xml)
|--- pom.xml
|--- Packaging: war

我的文件看起来像这样(许多依赖项,我认为我删除了不必要的使我的问题更清晰) 项目pom.xml:

<modelVersion>4.0.0</modelVersion>
<artifactId>project</artifactId>
<packaging>pom</packaging>
<name>Project - Modules</name>
<version>1.0.0-SNAPSHOT</version>

<parent>
    <groupId>com.project</groupId>
    <artifactId>project-parent-parent</artifactId>
    <version>2.0.0</version>
    <relativePath />
</parent>
<modules>
    <module>/project-war</module>
    <module>/project-common</module>
</modules>

Project-Common pom.xml:

<modelVersion>4.0.0</modelVersion>
<artifactId>project-common</artifactId>
<packaging>jar</packaging>
<name>Project - Common</name>
<version>1.0.0-SNAPSHOT</version>

<parent>
    <groupId>com.project</groupId>
    <artifactId>project-parent</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <relativePath />
</parent>

<build>
    <plugins>
        <plugin>
          <groupId>com.github.koraktor</groupId>
          <artifactId>mavanagaiata</artifactId>
          <executions>
            <execution>
              <id>load-git-branch</id>
              <phase>validate</phase>
              <goals>
                <goal>commit</goal>
              </goals>
              <configuration>
                <dirtyFlag>*</dirtyFlag>
                <gitDir>../../.git</gitDir>
              </configuration>
            </execution>
          </executions>
        </plugin>
     </plugins>
 </build>

Project-War pom.xml:

<modelVersion>4.0.0</modelVersion>
<artifactId>project-war</artifactId>
<version>1.1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>Project - WAR</name>

<parent>
    <groupId>com.project</groupId>
    <artifactId>parent-project</artifactId>
    <version>1.0.0-SNAPSHOT</version>
</parent>   

<dependencies>
    <dependency>
        <groupId>com.project</groupId>
        <artifactId>project-common</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>gwt-maven-plugin</artifactId>
            <version>2.7.0</version>
            <inherited>true</inherited>
            <configuration>
                <runTarget>/test.html</runTarget>
                <modules>
                    <module>com.project.modules.Test</module>
                </modules>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2.1</version>
            <executions>
                <execution>
                    <phase>process-classes</phase>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                    <configuration>
                        <id>VerifyRequestFactoryInterfaces</id>
                        <executable>java</executable>
                        <arguments>
                            <argument>-cp</argument>
                            <classpath />
                            <argument>com.google.web.bindery.requestfactory.apt.ValidationTool</argument>
                            <argument>${project.build.outputDirectory}</argument>
                            <argument>com.project.factorys.TestRequestFactory</argument>
                        </arguments>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <artifactId>maven-clean-plugin</artifactId>
            <version>2.4.1</version>
            <configuration>
                <filesets>
                    <fileset>
                        <directory>src/main</directory>
                        <includes>
                            <directory>gwt-unitCache/**</directory>
                        </includes>
                    </fileset>
                </filesets>
            </configuration>
        </plugin>
        <plugin>
          <groupId>com.github.koraktor</groupId>
          <artifactId>mavanagaiata</artifactId>
          <executions>
            <execution>
              <id>load-git-branch</id>
              <phase>validate</phase>
              <goals>
                <goal>commit</goal>
              </goals>
              <configuration>
                <dirtyFlag>*</dirtyFlag>
                <gitDir>../../.git</gitDir>
              </configuration>
            </execution>
          </executions>
        </plugin>
    </plugins>
</build>

旧项目在我的项目战中,我添加了Project&amp;项目常见。在这个设置中,项目构建并且我得到了新的&#34; Project-War.war。 但是当我将一个ErrorCode.java从Project-War移动到Project-Common时,我得到以下错误:

  

[INFO]跟踪类型&#39; com.project.modules.TestViewImpl&#39;的编译失败路径。   [INFO] [错误]&#39; ... / project / project-war / src / main / java / com / project / modules / TestViewImpl.java中的错误&#39;   [INFO] [ERROR]第20行:没有源代码可用于类型com.project.errorcodes.ErrorCode;你忘了继承一个必需的模块吗?   [INFO] [ERROR]提示:检查模块的继承链;它可能没有继承所需的模块,或者模块可能没有正确添加其源路径条目

2 个答案:

答案 0 :(得分:0)

您的项目 - Common并没有将其资源打包为可用于Project-War,因此GWT实际上无法找到ErrorCodes类的来源。

您必须使用Project-Common中的maven-source-plugin jar-no-fork目标打包来源,然后使用{{在Project-War中为Project-Common添加第二个依赖项1}};或者将您的<classifier>sources</classifier>声明为资源目录,以便将资源打包到Project-Common的JAR中。

作为旁注,Mojo的GWT Maven插件并不适合多模块项目。我建议切换到专为多模块构建而设计的net.ltgt.gwt.maven:gwt-maven-plugin(免责声明:我是该插件的作者,以及Mojo插件的前维护者) )

答案 1 :(得分:0)

找到解决方案:

在Common-Project中添加了一个模块

<module>
 <inherits name='com.google.gwt.activity.Activity' />
 <inherits name='com.google.gwt.place.Place' />
 <inherits name="com.google.gwt.user.User" />
 <inherits name='com.google.web.bindery.requestfactory.RequestFactory' />
 <inherits name="com.google.gwt.user.cellview.CellView" />
 <inherits name='com.google.gwt.logging.Logging' />
 <inherits name="com.google.gwt.inject.Inject" />
 <inherits name="com.google.gwt.text.Text" />
 <inherits name="com.google.gwt.i18n.I18N" />

 <inherits name="com.google.gwt.debug.Debug" />

 <source path="shared"/>
</module>

任何我的ErrorCode.java都在Path shared / **下。

在项目 - 战争模块中,我添加了<inherits name="com.project.Common" />和来自Project-War的pom.xml:

<dependency>
 <groupId>com.project</groupId>
 <artifactId>project-common</artifactId>
 <version>1.0.0-SNAPSHOT</version>
 <scope>compile</scope>
</dependency>
<dependency>
 <groupId>com.project</groupId>
 <artifactId>project-common</artifactId>
 <version>1.0.0-SNAPSHOT</version>
 <classifier>sources</classifier>
 <scope>provided</scope>
</dependency>

似乎需要在提供的范围内使用分类器进行依赖。