Gwt Maven多模块。如何配置依赖项以将Request Factory Proxies放入共享模块?

时间:2015-10-02 11:55:34

标签: java xml maven gwt multi-module

Gwt项目由3部分组成:clientsharedserver

我想用maven创建该结构,但是对于gwt app的每个部分,我想要单独的模块。

所以我有多模块maven项目。它由4个模块组成:

  1. 父模块
  2. 网络模块
  3. 共享模块
  4. 服务器模块
  5. 我想将Request Factory Proxies接口放在shared模块中。我怎么能这样做?

    我当前的pom.xml配置不允许我这样做。我收到了错误:

    Classes from server module cannot be resolved to a type

    这是我的配置:

    1。父模块没有任何类或GWT配置。 它只有pom.xml。它聚集了其余的模块。这是pom.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    
        <modelVersion>4.0.0</modelVersion>
        <groupId>com.test</groupId>
        <artifactId>parent</artifactId>
        <packaging>pom</packaging>
        <version>1.0.0-SNAPSHOT</version>
        <modules>
            <module>server</module>
            <module>shared</module>
            <module>web</module>
        </modules>
    
        <dependencies>
        </dependencies>
    
    
        <build>
        </build>
    </project>
    

    2。 Web模块具有pom.xmlgwt.xml配置。 xml配置

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xml>
    <module rename-to='parent'>
        <inherits name='com.google.gwt.user.User' />
        <inherits name='com.google.web.bindery.requestfactory.RequestFactory' />
    
        <!-- Application module inherits -->
        <inherits name="pl.derp.shared" />
        <inherits name="pl.derp.server" />
    
        <!-- Specify the app entry point class. -->
        <entry-point class='pl.derp.web.Parent2' />
    
        <!-- Specify the paths for translatable code -->
        <source path='web' />
    </module>
    

    pom.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <parent>
            <groupId>pl.derp</groupId>
            <artifactId>parent</artifactId>
            <version>1.0.0-SNAPSHOT</version>
        </parent>
    
        <artifactId>web</artifactId>
        <packaging>war</packaging>
    
        <dependencies>
            <dependency>
                <groupId>pl.derp</groupId>
                <artifactId>shared</artifactId>
                <version>${project.version}</version>
            </dependency>
            <dependency>
                <groupId>pl.derp</groupId>
                <artifactId>server</artifactId>
                <version>${project.version}</version>
            </dependency> 
        </dependencies>
    
        <build>
        </build>
    </project>
    

    第3。共享模块具有pom.xmlgwt.xml配置。 xml配置

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xml>
    <module rename-to='shared'>
        <inherits name="com.google.gwt.user.User"/>
    
        <source path="web"/>
        <source path="shared"/>
    </module>
    

    pom.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <parent>
            <groupId>pl.derp</groupId>
            <artifactId>parent</artifactId>
            <version>1.0.0-SNAPSHOT</version>
        </parent>
    
        <artifactId>shared</artifactId>
        <packaging>jar</packaging>
        <dependencies>
        </dependencies>
            <build>
            </build>
        </project>
    

    4。服务器模块具有pom.xmlgwt.xml配置。 xml配置

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xml>
    <module rename-to='server'>
        <inherits name="com.google.gwt.user.User"/>
    
        <inherits name="pl.derp.shared"/>
    
        <source path="server"/>
    </module>
    

    pom.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <parent>
            <groupId>pl.derp</groupId>
            <artifactId>parent</artifactId>
            <version>1.0.0-SNAPSHOT</version>
        </parent>
    
        <artifactId>server</artifactId>
        <packaging>jar</packaging>
    
        <properties>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>pl.derp</groupId>
                <artifactId>shared</artifactId>
                <version>${project.version}</version>
            </dependency>
        </dependencies>
    
    
        <build>
        </build>
    </project>
    

    请帮帮我。

    修改

    新的maven依赖命题:

    父模块

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
    
      <groupId>com</groupId>
      <artifactId>mrf</artifactId>
      <version>1.0-SNAPSHOT</version>
      <packaging>pom</packaging>
    
      <prerequisites>
        <maven>${mavenVersion}</maven>
      </prerequisites>
    
      <modules>
        <module>mrf-domain</module>
        <module>mrf-server</module>
        <module>mrf-shared</module>
        <module>mrf-client</module>
      </modules>
    
      <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    
        <mavenVersion>3.0</mavenVersion>
      </properties>
    
      <dependencyManagement>
        <dependencies>
          <dependency>
            <groupId>com.google.gwt</groupId>
            <artifactId>gwt</artifactId>
            <version>2.7.0</version>
            <type>pom</type>
            <scope>import</scope>
          </dependency>
          <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
            <scope>provided</scope>
          </dependency>
        </dependencies>
      </dependencyManagement>
    
      <build>
        <plugins>
          <plugin>
            <groupId>net.ltgt.gwt.maven</groupId>
            <artifactId>gwt-maven-plugin</artifactId>
            <inherited>false</inherited>
            <configuration>
              <launcherDir>${project.build.directory}/gwt/launcherDir</launcherDir>
            </configuration>
          </plugin>
        </plugins>
        <pluginManagement>
          <plugins>
            <plugin>
              <artifactId>maven-compiler-plugin</artifactId>
              <version>3.2</version>
              <configuration>
                <source>1.7</source>
                <target>1.7</target>
              </configuration>
            </plugin>
            <plugin>
              <groupId>org.eclipse.jetty</groupId>
              <artifactId>jetty-maven-plugin</artifactId>
              <version>9.2.3.v20140905</version>
            </plugin>
            <plugin>
              <groupId>net.ltgt.gwt.maven</groupId>
              <artifactId>gwt-maven-plugin</artifactId>
              <version>1.0-rc-2</version>
              <extensions>true</extensions>
              <configuration>
                <sourceLevel>1.7</sourceLevel>
                <failOnError>true</failOnError>
              </configuration>
            </plugin>
            <plugin>
              <artifactId>maven-source-plugin</artifactId>
              <version>2.4</version>
              <executions>
                <execution>
                  <id>attach-sources</id>
                  <phase>package</phase>
                  <goals>
                    <goal>jar-no-fork</goal>
                  </goals>
                </execution>
              </executions>
            </plugin>
            <plugin>
              <groupId>org.apache.tomcat.maven</groupId>
              <artifactId>tomcat6-maven-plugin</artifactId>
              <version>2.2</version>
            </plugin>
            <plugin>
              <groupId>org.apache.tomcat.maven</groupId>
              <artifactId>tomcat7-maven-plugin</artifactId>
              <version>2.2</version>
            </plugin>
            <plugin>
              <groupId>org.codehaus.mojo</groupId>
              <artifactId>exec-maven-plugin</artifactId>
              <version>1.3.2</version>
            </plugin>
          </plugins>
        </pluginManagement>
      </build>
    
    </project>
    

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
    
      <parent>
        <groupId>com</groupId>
        <artifactId>mrf</artifactId>
        <version>1.0-SNAPSHOT</version>
      </parent>
    
      <artifactId>mrf-domain</artifactId>
    
      <prerequisites>
        <maven>${mavenVersion}</maven>
      </prerequisites>
    
    
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-source-plugin</artifactId>
          </plugin>
        </plugins>
      </build>
    </project>
    

    服务器:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
    
      <parent>
        <groupId>com</groupId>
        <artifactId>mrf</artifactId>
        <version>1.0-SNAPSHOT</version>
      </parent>
    
      <artifactId>mrf-server</artifactId>
      <packaging>war</packaging>
    
      <prerequisites>
        <maven>${mavenVersion}</maven>
      </prerequisites>
    
      <dependencies>
    
    
        <dependency>
          <groupId>${project.groupId}</groupId>
          <artifactId>mrf-shared</artifactId>
          <version>${project.version}</version>
        </dependency>
    
    
        <dependency>
          <groupId>com.google.web.bindery</groupId>
          <artifactId>requestfactory-apt</artifactId>
        </dependency>
        <dependency>
          <groupId>com.google.web.bindery</groupId>
          <artifactId>requestfactory-server</artifactId>
        </dependency>
        <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>javax.servlet-api</artifactId>
        </dependency>
      </dependencies>
    
      <build>
        <plugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <executions>
              <execution>
                <phase>process-classes</phase>
                <id>requestfactory-validation-tool</id>
                <goals>
                  <goal>exec</goal>
                </goals>
                <configuration>
                  <executable>java</executable>
                  <classpathScope>compile</classpathScope>
                  <arguments>
                    <argument>-Dverbose=true</argument>
                    <argument>-cp</argument>
                    <classpath />
                    <argument>com.google.web.bindery.requestfactory.apt.ValidationTool</argument>
                    <argument>${project.build.outputDirectory}</argument>
                    <argument>pl.AppFactory</argument>
                  </arguments>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
        <pluginManagement>
          <plugins>
                    <!--This plugin's configuration is used to store Eclipse m2e settings 
                        only. It has no influence on the Maven build itself. -->
            <plugin>
              <groupId>org.eclipse.m2e</groupId>
              <artifactId>lifecycle-mapping</artifactId>
              <version>1.0.0</version>
              <configuration>
                <lifecycleMappingMetadata>
                  <pluginExecutions>
                    <pluginExecution>
                      <pluginExecutionFilter>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <versionRange>[1.2,)</versionRange>
                        <goals>
                          <goal>exec</goal>
                        </goals>
                      </pluginExecutionFilter>
                      <action>
                        <ignore />
                      </action>
                    </pluginExecution>
                  </pluginExecutions>
                </lifecycleMappingMetadata>
              </configuration>
            </plugin>
          </plugins>
        </pluginManagement>
      </build>
    
      <profiles>
        <profile>
          <!-- XXX: We want to exclude mrf-client from 'env-dev' profile, Maven forces us to make a 'env-prod' profile -->
          <id>env-prod</id>
          <activation>
            <activeByDefault>true</activeByDefault>
          </activation>
          <dependencies>
            <dependency>
              <groupId>${project.groupId}</groupId>
              <artifactId>mrf-client</artifactId>
              <version>${project.version}</version>
              <type>war</type>
              <scope>runtime</scope>
            </dependency>
          </dependencies>
        </profile>
        <profile>
          <id>env-dev</id>
          <activation>
            <property>
              <name>env</name>
              <value>dev</value>
            </property>
          </activation>
          <build>
            <pluginManagement>
              <plugins>
                <plugin>
                  <groupId>org.eclipse.jetty</groupId>
                  <artifactId>jetty-maven-plugin</artifactId>
                  <configuration>
                    <scanIntervalSeconds>1</scanIntervalSeconds>
                    <webApp>
                      <baseResource implementation="org.eclipse.jetty.util.resource.ResourceCollection">
                        <resourcesAsCSV>src/main/webapp,${basedir}/../target/gwt/launcherDir/</resourcesAsCSV>
                      </baseResource>
                      <extraClasspath>${basedir}/../mrf-shared/target/classes/</extraClasspath>
                      <extraClasspath>${basedir}/../mrf-domain/target/classes/</extraClasspath>
                    </webApp>
                  </configuration>
                </plugin>
                <plugin>
                  <groupId>org.apache.tomcat.maven</groupId>
                  <artifactId>tomcat6-maven-plugin</artifactId>
                  <configuration>
                    <addWarDependenciesInClassloader>false</addWarDependenciesInClassloader>
                    <contextFile>${basedir}/src/main/tomcatconf/context.xml</contextFile>
                    <path>/</path>
                    <uriEncoding>UTF-8</uriEncoding>
                  </configuration>
                </plugin>
                <plugin>
                  <groupId>org.apache.tomcat.maven</groupId>
                  <artifactId>tomcat7-maven-plugin</artifactId>
                  <configuration>
                    <addWarDependenciesInClassloader>false</addWarDependenciesInClassloader>
                    <contextFile>${basedir}/src/main/tomcatconf/context.xml</contextFile>
                    <path>/</path>
                    <uriEncoding>UTF-8</uriEncoding>
                  </configuration>
                </plugin>
              </plugins>
            </pluginManagement>
          </build>
        </profile>
      </profiles>
    </project>
    

    共享

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
    
      <parent>
        <groupId>com</groupId>
        <artifactId>mrf</artifactId>
        <version>1.0-SNAPSHOT</version>
      </parent>
    
      <artifactId>mrf-shared</artifactId>
    
      <prerequisites>
        <maven>${mavenVersion}</maven>
      </prerequisites>
    
      <dependencies>
        <dependency>
          <groupId>${project.groupId}</groupId>
          <artifactId>mrf-domain</artifactId>
          <version>${project.version}</version>
        </dependency>
    
    
        <dependency>
          <groupId>com.google.web.bindery</groupId>
          <artifactId>requestfactory-apt</artifactId>
        </dependency>
        <dependency>
          <groupId>com.google.web.bindery</groupId>
          <artifactId>requestfactory-server</artifactId>
        </dependency>
        <dependency>
          <groupId>com.google.web.bindery</groupId>
          <artifactId>requestfactory-client</artifactId>
          <scope>provided</scope>
        </dependency>
      </dependencies>
    
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-source-plugin</artifactId>
          </plugin>
        </plugins>
      </build>
    </project>
    

    客户端

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
    
      <parent>
        <groupId>com</groupId>
        <artifactId>mrf</artifactId>
        <version>1.0-SNAPSHOT</version>
      </parent>
    
      <artifactId>mrf-client</artifactId>
      <packaging>gwt-app</packaging>
    
      <prerequisites>
        <maven>${mavenVersion}</maven>
      </prerequisites>
    
      <dependencies>
        <dependency>
          <groupId>${project.groupId}</groupId>
          <artifactId>mrf-shared</artifactId>
          <version>${project.version}</version>
        </dependency>
        <dependency>
          <groupId>${project.groupId}</groupId>
          <artifactId>mrf-shared</artifactId>
          <version>${project.version}</version>
          <classifier>sources</classifier>
        </dependency>
        <dependency>
          <groupId>com.google.gwt</groupId>
          <artifactId>gwt-user</artifactId>
        </dependency>
        <dependency>
          <groupId>com.google.gwt</groupId>
          <artifactId>gwt-dev</artifactId>
        </dependency>
        <dependency>
          <groupId>com.google.gwt</groupId>
          <artifactId>gwt-codeserver</artifactId>
        </dependency>
      </dependencies>
    
      <build>
        <plugins>
          <plugin>
            <groupId>net.ltgt.gwt.maven</groupId>
            <artifactId>gwt-maven-plugin</artifactId>
            <configuration>
              <moduleName>pl.App</moduleName>
              <moduleShortName>mrf</moduleShortName>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </project>
    

    不幸的是,当我尝试在proxy课程中使用时: @ProxyFor(pl.domain.GreetingResponse2.class)

    我收到错误:

    [INFO] ------------------------------------------------------------------------
    [INFO] Reactor Summary:
    [INFO] 
    [INFO] mrf ............................................... SUCCESS [0.106s]
    [INFO] mrf-domain ........................................ SUCCESS [0.893s]
    [INFO] mrf-shared ........................................ SUCCESS [0.277s]
    [INFO] mrf-client ........................................ SUCCESS [6.519s]
    [INFO] mrf-server ........................................ FAILURE [0.599s]
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 8.824s
    [INFO] Finished at: Mon Oct 05 13:33:27 CEST 2015
    [INFO] Final Memory: 28M/311M
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.3.2:exec (requestfactory-validation-tool) on project mrf-server: Command execution failed. Process exited with an error: 255 (Exit value: 255) -> [Help 1]
    org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.3.2:exec (requestfactory-validation-tool) on project mrf-server: Command execution failed.
    

    当我使用:@ProxyForName("pl.server.GreetingResponse")时,编译正常。请帮忙。

2 个答案:

答案 0 :(得分:1)

您可以shared(和client)取决于server,因此您可以引用@ProxyFor@Service的服务器端类;但是你冒险从共享和客户端代码引用服务器端类,并且在使用GWT编译器或devmode(即延迟)时只注意它,因此在使用多模块Maven项目时绝对没有任何好处。

或者您可以使用@ProxyForName@ServiceName通过隐含shared来放宽server上的依赖关系。这种方式client仅取决于shared而不依赖server 您可以在https://github.com/tbroyer/gwt-maven-archetypes

modular-requestfactory Maven原型中查看该方法的示例

顺便说一句,我认为server + shared + client三人组成为单个&#34;单位&#34; (仅人为地分成3层以适应Maven限制以及依赖范围等),我只是让它们共享一个共同的根包(有或没有serversharedclient子包)。这样我可以在*.gwt.xml模块中使用单个client,在GWT&#34;源路径&#34;中提供客户端和共享文件。并且shared模块对GWT没有依赖性(providedrequestfactory-client只有requestfactory-server依赖; client将使用gwt-user代替, server将使用requestfactory-servergwt-servlets)。

答案 1 :(得分:0)

你必须尊重maven结构。 在具有每个模块的pom的目​​录中,您必须具有目录/ src,您必须在其中保存源。

Maven在构建模块时查找此目录。 在这里,您可以阅读有关此https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html

的更多信息

但我不建议您更改GWT应用程序的标准结构。

考虑一下想要进一步研究代码的开发人员。他们会期待标准,并且他们最初很难理解结构。

相关问题