Maven-war-plugin: exclude all but one directory

I have a directory structure like:

screenshot

src |__ main |__ java |__ resources |__ webapp |__ css_blue |__ css_green |__ css_red |__ WEB-INF 

where there are three separate css directories (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, the files and directories under WEB-INF not present in the final .war file.

+5
source share
1 answer

By default, the packagingIncludes maven-war-plugin attribute will contain everything under src/main/webapp . When you override it to indicate

 <packagingIncludes>css_${css}/**</packagingIncludes> 

then the plugin will only include this folder (and everything under it), rather than WEB-INF . A simple solution is to re-enable WEB-INF :

 <packagingIncludes>WEB-INF/**,css_${css}/**</packagingIncludes> 

With this 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 instead of <packagingExcludes> . Thus, all files under src/main/webapp will be included, except for those that we specify here. In this case, we can use a regular expression that says: exclude everything that starts with css and not css_${css} .

 <packagingExcludes>%regex[css_(?!${css}/).*]</packagingExcludes> 
+2
source

Source: https://habr.com/ru/post/1239878/


All Articles