How to exclude jars generated by maven war plugin ?

Posted on Updated on

maven
There are various way to exclude jar files generated by Maven pom file.

1. Using <packagingExcludes> tags we can exclude files.

<plugin>
  <groupid>org.apache.maven.plugins</groupid>
  <artifactid>maven-war-plugin</artifactid>
  <configuration>
   <archive>
    <manifest>
     <mainclass>com.project</mainclass>
     <addclasspath>true</addclasspath>
    </manifest>
    <manifestentries>
     <mode>development</mode>
     <url>${project.url}</url>
     <splashscreen-image>Image-Filename.png</splashscreen-image>
    </manifestentries>
   </archive>
    <packagingexcludes>WEB-INF/lib/commons*.jar,WEB-INF/lib/dom4*.jar
   </packagingexcludes>
    <webxml>${basedir}/src/main/webapp/WEB-INF/web.xml</webxml>
    <warname>finalProject</warname>
   <warsourcedirectory>src/main/webapp</warsourcedirectory>
  </configuration>
</plugin>

2. We can excluded jar base on their artifactid or groupid.

<dependency>
 <groupId>org.apache.cxf</groupId>
 <artifactId>cxf-rt-frontend-jaxws</artifactId>
 <version>${cxf.version}</version>

 <exclusions>
  <exclusion>
   <groupId>org.apache.geronimo.specs</groupId>
   <artifactId>geronimo-javamail_1.4_spec</artifactId>
  </exclusion>
 </exclusions>
</dependency>

Hidden Commands of Maven

mvn tree

view the dependency hierarchy of the project currently being built.

mvn dependency:analyze

performs byte code analysis to determine missing or unused dependencies. This goal is meant to be launched from the command line. It will fork the build and execute test-compile so there are class files to analyze. If you want to bind analyze in your pom, use the dependency:analyze-only mojo instead.

Leave a comment