Maven - Exclude class files from war

I have:

Src / main / java / com.tuto
|
-Class1.java
-Class2.java
-Class3.java

My pom packs the war. Therefore, in my war in WEB-INF / classes / com / tuto I found 3 classes.

Now I want to exclude Class2.java

I tried

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.1</version> <configuration> <excludes> <exclude>**/Class2.class</exclude> </excludes> </configuration> </plugin> 

But it does not work.

How can i do this?


Okay, so, as Aaron says, this works:

 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.1</version> <configuration> <packagingExcludes>**/Class2.class</packagingExcludes> </configuration> </plugin> 

But...

Let's take the problem from the other side: I want to exclude everything except Class1 and Class3

So i tried

 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.1</version> <configuration> <packagingIncludes>**/Class1.class,**/Class3.class</packagingIncludes> </configuration> </plugin> 

and this time it does not work.

+4
source share
4 answers

As the documentation says , you should use the packagingExcludes element.

Please note that packagingExcludes does not use nested elements. Instead, the content is a "comma-separated list of Ant file set templates."

+8
source

An exception will include a higher priority from the documentation . In your case, use packageExcludes to explicitly exclude class2.

 <packagingExcludes>WEB-INF/classes/com/tuto/Class2.class</packagingExcludes> 
+1
source

The full xml plugin should look like this:

 <plugin> <artifactId>maven-war-plugin</artifactId> <configuration> <outputDirectory>${build.output.directory}</outputDirectory> <packagingExcludes>WEB-INF/classes/ItemConsumer.class</packagingExcludes> </configuration> </plugin> 
0
source

add a plugin to pom.xml - 100% workable.

 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.3</version> <configuration> <!--package path you want to delete--> <packagingExcludes>WEB-INF/classes/lk/**</packagingExcludes> <webResources> <resource> <!--project build path--> <directory>${project.basedir}/target/classes/</directory> <filtering>true</filtering> <includes><include>**/*.class</include></includes> </resource> </webResources> </configuration> </plugin> 
0
source

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


All Articles