I have a directory structure as:
src
|__ main
|__ java
|__ resources
|__ webapp
|__ css_blue
|__ css_green
|__ css_red
|__ WEB-INF
where there are three seperate directories of css (as css_red
, css_green
, css_blue
). Here, I want to include only one of them based on the -D
switch as:
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>
But in this case files and directories under WEB-INF
not present in the final .war
file.
By default, the packagingIncludes
attribute of the maven-war-plugin
will include everything under src/main/webapp
. When you override it to specify
<packagingIncludes>css_${css}/**</packagingIncludes>
then the plugin will only include that folder (and everything under it) and not WEB-INF
anymore. A simple solution is to re-include WEB-INF
:
<packagingIncludes>WEB-INF/**,css_${css}/**</packagingIncludes>
With such a configuration, everything under WEB-INF
and everything under css_${css}
will be included in the war.
Another solution that does not require re-adding folders would be to use <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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With