maven-war-plugin: 排除除一个以外的所有目录
maven-war-plugin: exclude all directories but one
我的目录结构如下:
src
|__ main
|__ java
|__ resources
|__ webapp
|__ css_blue
|__ css_green
|__ css_red
|__ WEB-INF
其中有 css 的三个独立目录(如 css_red
、css_green
、css_blue
)。在这里,我只想包含基于 -D
开关的其中一个:
mvn clean install -Dcss=green
pom.xml
<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.faisal.dwr</groupId>
<artifactId>chatbox</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<!-- Spring - MVC -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.2.4.RELEASE</version>
</dependency>
<!-- Spring Web Security -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>4.0.3.RELEASE</version>
</dependency>
<!-- Spring Security Config -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>4.0.3.RELEASE</version>
</dependency>
<!-- DWR -->
<dependency>
<groupId>org.directwebremoting</groupId>
<artifactId>dwr</artifactId>
<version>3.0.0-RELEASE</version>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<packagingIncludes>css_${css}</packagingIncludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
但在这种情况下,WEB-INF
下的文件和目录不存在于最终的 .war
文件中。
默认情况下,maven-war-plugin
的 packagingIncludes
属性将包含 src/main/webapp
下的所有内容。当您覆盖它以指定
<packagingIncludes>css_${css}/**</packagingIncludes>
然后插件将只包含该文件夹(及其下的所有内容),而不是 WEB-INF
。一个简单的解决方案是 re-include WEB-INF
:
<packagingIncludes>WEB-INF/**,css_${css}/**</packagingIncludes>
通过这样的配置,WEB-INF
下的所有内容和 css_${css}
下的所有内容都将包含在 war.
中
另一个不需要 re-adding 文件夹的解决方案是使用 <packagingExcludes>
instead. This way, all files under src/main/webapp
will be included, except those that we specify here. In this case, we can use a regular expression that says: exclude everything that starts with css
and is not css_${css}
.
<packagingExcludes>%regex[css_(?!${css}/).*]</packagingExcludes>
我的目录结构如下:
src
|__ main
|__ java
|__ resources
|__ webapp
|__ css_blue
|__ css_green
|__ css_red
|__ WEB-INF
其中有 css 的三个独立目录(如 css_red
、css_green
、css_blue
)。在这里,我只想包含基于 -D
开关的其中一个:
mvn clean install -Dcss=green
pom.xml
<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.faisal.dwr</groupId>
<artifactId>chatbox</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<!-- Spring - MVC -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.2.4.RELEASE</version>
</dependency>
<!-- Spring Web Security -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>4.0.3.RELEASE</version>
</dependency>
<!-- Spring Security Config -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>4.0.3.RELEASE</version>
</dependency>
<!-- DWR -->
<dependency>
<groupId>org.directwebremoting</groupId>
<artifactId>dwr</artifactId>
<version>3.0.0-RELEASE</version>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<packagingIncludes>css_${css}</packagingIncludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
但在这种情况下,WEB-INF
下的文件和目录不存在于最终的 .war
文件中。
默认情况下,maven-war-plugin
的 packagingIncludes
属性将包含 src/main/webapp
下的所有内容。当您覆盖它以指定
<packagingIncludes>css_${css}/**</packagingIncludes>
然后插件将只包含该文件夹(及其下的所有内容),而不是 WEB-INF
。一个简单的解决方案是 re-include WEB-INF
:
<packagingIncludes>WEB-INF/**,css_${css}/**</packagingIncludes>
通过这样的配置,WEB-INF
下的所有内容和 css_${css}
下的所有内容都将包含在 war.
另一个不需要 re-adding 文件夹的解决方案是使用 <packagingExcludes>
instead. This way, all files under src/main/webapp
will be included, except those that we specify here. In this case, we can use a regular expression that says: exclude everything that starts with css
and is not css_${css}
.
<packagingExcludes>%regex[css_(?!${css}/).*]</packagingExcludes>