Gwt项目由3部分组成:客户端
、共享
和服务器
。
我想使用 Maven 创建该结构,但对于 gwt 应用程序的每个部分,我希望有单独的模块。
所以我有多模块 Maven 项目。它由4个模块组成:
- 父模块
- 网络模块
- 共享模块
- 服务器模块
我想将Request Factory Proxies
接口(interface)放入shared
模块中。我怎样才能做到这一点?
我当前的 pom.xml 配置不允许我这样做。我收到错误:
服务器模块中的类无法解析为类型
这是我的配置:
<小时/><强>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.xml
和gwt.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.xml
和gwt.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.xml
和gwt.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")
时,它编译得很好。请帮忙。
最佳答案
您可以让共享
(和客户端
)依赖于服务器
,这样您就可以从@ProxyFor引用服务器端类
和 @Service
;但是这样您就会冒着从共享和客户端代码引用服务器端类的风险,并且只有在使用 GWT 编译器或 devmode(即晚期)时才会注意到它,因此在使用多模块 Maven 项目时绝对没有任何好处。
或者您可以使用@ProxyForName
和@ServiceName
,通过使server
放松对shared
的依赖它是隐含的;这样客户端
仅依赖于共享
,而不依赖于服务器
。
您可以在 modular-requestfactory
Maven 原型(prototype) https://github.com/tbroyer/gwt-maven-archetypes 中看到该方法的示例。
顺便说一句,我认为服务器
+共享
+客户端
三重奏是一个单一的“单元”(只是人为地分成3层适应 Maven 对依赖范围等的限制),我只是让它们共享一个公共(public)根包(有或没有服务器
、共享
和客户端
) > 子包)。这样我就可以在 client
模块中拥有一个 *.gwt.xml
,将客户端文件和共享文件带到 GWT 的“源路径”中;并且 shared
模块对 GWT 的依赖关系为零(仅对 requestfactory-client
或 requestfactory-server
具有 provided
依赖关系>; client
将使用 gwt-user
代替,server
将使用 requestfactory-server
或 gwt -servlet
)。
关于java - Gwt Maven 多模块。如何配置依赖项以将请求工厂代理放入共享模块中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32906646/