I have :
src/main/java/com.tuto
Class1.java
Class2.java
Class3.java
My pom is packaging a war.
So in my war, in WEB-INF/classes/com/tuto
I found the 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's not working.
How can I do ?
Ok, so like Aaron tell me, this is working :
<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 by the other side : I want to exclude all 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's not working.
It is possible to include or exclude certain files from the WAR file, by using the <packagingIncludes> and <packagingExcludes> configuration parameters.
Since Maven resolves dependencies transitively, it is possible for unwanted dependencies to be included in your project's classpath. For example, a certain older jar may have security issues or be incompatible with the Java version you're using. To address this, Maven allows you to exclude specific dependencies.
You can use a diagram to exclude a dependency from the project's POM. Select a dependency in the diagram window. From the context menu, choose Exclude. From the list, select the module (if any) where the exclusion definition will be added.
xml file to exclude property files. You need to specify the directory where the files are reside in your application structure. Also you need to specify the file types to be excluded using exclude tag.
As the documentation says, you should use the packagingExcludes
element instead.
Note that packagingExcludes
doesn't use nested elements. Instead, the content is a "comma-separated list of Ant file set patterns".
From the documentation, excludes will take higher priority over includes. In your case, use packagingExcludes for excluding class2 explicitly.
<packagingExcludes>WEB-INF/classes/com/tuto/Class2.class</packagingExcludes>
The complete plugin xml should be like the following
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<outputDirectory>${build.output.directory}</outputDirectory>
<packagingExcludes>WEB-INF/classes/ItemConsumer.class</packagingExcludes>
</configuration>
</plugin>
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