maven-war-plugin: exclude all directories but one

Mohammad Faisal

I have a directory structure as:

screenshot

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.

Tunaki

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>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Maven war plugin archiveClasses but exclude a package

From Dev

How to exclude certain resources from the maven war plugin war file?

From Dev

Filtering in maven-war-plugin does not exclude directory

From Dev

Filtering in maven-war-plugin does not exclude directory

From Dev

Sonar Maven Plugin: How do I exclude test source directories?

From Dev

Fortify SCA exclude multiple directories/files with maven plugin

From Dev

maven-clean-plugin is not removing all given directories

From Dev

maven-shade-plugin : exclude a dependency and all its transitive dependencies

From Dev

maven exclude plugin in dependency

From Dev

Deploy war with Jetty maven plugin

From Dev

Maven war plugin not filtering as expected

From Dev

When building an application jar with Maven Shade, is it safe to exclude all META-INF/versions directories/files?

From Dev

Maven - Exclude class files from war

From Dev

Conditionally exclude some resources in maven from war

From Dev

Maven - Exclude class files from war

From Dev

maven - how to exclude an entire module on from war

From Dev

SpotBugs Maven Plugin exclude a directory

From Dev

Maven war plugin copy arbitrary files

From Dev

Use Maven Replacer Plugin Before WAR is Packaged

From Dev

maven-war-plugin and the Spring JavaConfig

From Dev

maven-war-plugin not filtering on local

From Dev

using maven-war-plugin with Spring BOM

From Dev

Maven-war-plugin - remove files

From Dev

maven-war-plugin include subdirectories

From Dev

malformed pom error with maven war plugin

From Dev

maven-war-plugin ignores <archiveClasses>

From Dev

How to filter applicationContext using maven war plugin

From Dev

Wildfly-Maven-Plugin only Ear and War

From Dev

maven war plugin put my resources in war root directory

Related Related

  1. 1

    Maven war plugin archiveClasses but exclude a package

  2. 2

    How to exclude certain resources from the maven war plugin war file?

  3. 3

    Filtering in maven-war-plugin does not exclude directory

  4. 4

    Filtering in maven-war-plugin does not exclude directory

  5. 5

    Sonar Maven Plugin: How do I exclude test source directories?

  6. 6

    Fortify SCA exclude multiple directories/files with maven plugin

  7. 7

    maven-clean-plugin is not removing all given directories

  8. 8

    maven-shade-plugin : exclude a dependency and all its transitive dependencies

  9. 9

    maven exclude plugin in dependency

  10. 10

    Deploy war with Jetty maven plugin

  11. 11

    Maven war plugin not filtering as expected

  12. 12

    When building an application jar with Maven Shade, is it safe to exclude all META-INF/versions directories/files?

  13. 13

    Maven - Exclude class files from war

  14. 14

    Conditionally exclude some resources in maven from war

  15. 15

    Maven - Exclude class files from war

  16. 16

    maven - how to exclude an entire module on from war

  17. 17

    SpotBugs Maven Plugin exclude a directory

  18. 18

    Maven war plugin copy arbitrary files

  19. 19

    Use Maven Replacer Plugin Before WAR is Packaged

  20. 20

    maven-war-plugin and the Spring JavaConfig

  21. 21

    maven-war-plugin not filtering on local

  22. 22

    using maven-war-plugin with Spring BOM

  23. 23

    Maven-war-plugin - remove files

  24. 24

    maven-war-plugin include subdirectories

  25. 25

    malformed pom error with maven war plugin

  26. 26

    maven-war-plugin ignores <archiveClasses>

  27. 27

    How to filter applicationContext using maven war plugin

  28. 28

    Wildfly-Maven-Plugin only Ear and War

  29. 29

    maven war plugin put my resources in war root directory

HotTag

Archive