我正在尝试在另一场 war 中重用已组装的 gwt 编译。为此,我尝试更改当前 Maven 模块的包装 war
至pom
。然后,我计划使用 maven- assembly-plugin 来压缩 gwt 的模块 js 输出,并稍后在另一个 war 模块中使用它。
我尝试更改包装标签 <packaging>war</packaging>
至<packaging>pom</packaging>
在 pom.xml 中 Validation sample 。 gwt-maven-plugin 永远不会进入编译。相反,它会跳过编译!!!!!!
-
What is happening?
-
Is this expected?
-
Is there any workaround?
最佳答案
要将多个 gwt 编译模块加入到单个 .war
文件中,使用 maven-dependency-plugin 非常容易。
- 将所有 gwt 示例打包为习惯性的 (.war),如果您有私有(private) Maven 存储库,则使用
mvn install
或mvn deploy
安装它们。 - 创建一个
war
类型的空maven模块,没有任何代码,但具有maven文件夹结构,您可以在这里放置您需要的任何其他内容,例如全局src/main/webapp/index.html
. 配置新模块以使用
maven-dependency-plugin
,如下所示,然后运行mvn package
:<dependency> <groupId>my.group</groupId> <artifactId>example1</artifactId> <version>...</version> <type>war</type> </dependency> ... <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>unpack-gwt-examples</id> <phase>prepare-package</phase> <goals> <goal>unpack-dependencies</goal> </goals> <configuration> <includeGroupIds>my.group</includeGroupIds> <includes>**/example1/**</includes> <outputDirectory>${project.build.directory}/${project.artifactId}-${project.version}</outputDirectory> </configuration> </execution> </executions> </plugin>
最后,与 gwt-maven-plugin 相关,与任何其他 Maven 插件一样,选择 pom 打包生命周期的适当阶段(打包、安装或部署)就足够了:
...
<packaging>pom</packaging>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
...
<configuration>
...
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
不幸的是,gwt-maven-plugin 在打包为 pom 时明确禁止编译,请查看 line #269 of CompileMojo.java
关于模块打包为pom时,maven中会跳过GWT编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15563057/