我遇到了让Maven构建我的webapp而没有包含无关开发文件的问题,例如未经编辑的脚本和css文件。
首先,我尝试将exclude
与webResources
<build>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warName>ReportRocket-1</warName>
<webResources>
<resource>
<directory>src/main/webapp/resources/</directory>
<excludes>
<exclude>annotated-js/*.js</exclude>
<exclude>compiled-js/*.js</exclude>
<exclude>css/*.css</exclude>
<exclude>less/*.less/exclude>
</excludes>
<directory>src/main/webapp/WEB-INF</directory>
<excludes>
<exclude>connection.json</exclude>
<exclude>reportRocket.jsp</exclude>
</excludes>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
结果是WEB-INF
的内容在项目根目录中重复,没有排除的目录或文件。
所以,我在这里查看并找到了这个:maven2: excluding directory from WAR但使用mvn clean package
或warSourceExcludes
运行packagingExcludes
会导致我尝试排除的目录没有,好,排除......
我的pom.xml的构建部分
<build>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warName>ReportRocket-1</warName>
<packagingExcludes>
src/main/webapp/resources/annotated-js/,
src/main/webapp/resources/compiled-js/,
src/main/webapp/resources/css/,
src/main/webapp/resources/less/,
src/main/webapp/WEB-INF/connection.json
</packagingExcludes>
</configuration>
</plugin>
</plugins>
</build>
使用这些设置构建项目会产生以下项目结构:
META-INF
resources
//desired folders
annotated-js
compiled-js
css
less
WEB-INF
// desired files
connection.json
这是我第一次使用构建工具,所以我可能会忽略一些简单的东西,但与此同时,这让我发疯。我的xml有什么建议或明显的问题吗?
答案 0 :(得分:3)
首先,您应该阅读maven-war-plugin的文档,因为packagingExclude用于其他目的,但在您的情况下,您需要执行configuration in that way:
<configuration>
<webResources>
<resource>
<!-- this is relative to the pom.xml directory -->
<directory>src/main/webapp/resources/</directory>
<!-- there's no default value for this -->
<excludes>
<exclude>annotated-js/**</exclude>
</excludes>
</resource>
</webResources>
</configuration>