我正在将遗留的 Spring 项目构建脚本从 Ant 重写为 Maven。该项目有几个 GWT 模块,每个模块都编译为 JAR。当前的项目结构由几个Maven模块组成,或多或少是这样的:
mainProject
|- AnalyzerGWT <-- this module uses GWT
|- analyzer <-- this doesn't
|- someOtherModule
|- p4you-spring <-- this module has resources and builds WAR
每个使用 GWT 的模块在其 pom.xml 中都有以下代码(模块称为 AnalyzerGWT):
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<gwtSdkFirstInClasspath>true</gwtSdkFirstInClasspath>
<compileSourcesArtifacts>
<artifact>com.pamm:portal-common</artifact>
<artifact>com.pamm:analyzer</artifact>
</compileSourcesArtifacts>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
编译成功,结果 GWT 资源保存到AnalyzerGWT/target/AnalyzerGWT-1.0/com.pamm.analyzer.gwt.Analyzer/,但是该目录的内容不包含在结果中JAR 文件。
有没有一种优雅的方法可以将此目录的内容复制到 JAR 的根路径中?
最佳答案
我通过添加以下内容成功解决了该问题:
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
<resources>
<resource>
<directory>
${project.build.directory}/AnalyzerGWT-1.0/com.pamm.analyzer.gwt.Analyzer/
</directory>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
至 <plugins>
pom.xml 中的部分。
关于maven-gwt-plugin 并打包到 JAR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33610920/