Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude jars generated by maven war plugin?

Tags:

java

maven-2

Because of transitive dependencies, my wars are getting populated by xml-apis, xerces jars. I tried following the instructions on the reference page for maven-war-plugin but it is not working.

<plugin>     <groupId>org.apache.maven.plugins</groupId>     <artifactId>maven-war-plugin</artifactId>     <configuration>       <packagingExcludes>WEB-INF/lib/xalan-2.6.0.jar,WEB-INF/lib/xercesImpl-2.6.2.jar,WEB-INF/lib/xml-apis-1.0.b2.jar,WEB-INF/lib/xmlParserAPIs-2.6.2.jar</packagingExcludes>       <webXml>${basedir}/src/main/webapp/WEB-INF/web.xml</webXml>       <warName>project1</warName>       <warSourceDirectory>src/main/webapp</warSourceDirectory>     </configuration> </plugin> 

What am I doing wrong ? If it matters, I discovered that the maven-war-plugin I'm using is at version 2.1-alpha-1

like image 831
Jacques René Mesrine Avatar asked Jun 23 '09 10:06

Jacques René Mesrine


People also ask

How do I exclude a jar from pom?

We can have multiple transitive dependencies can be excluded by using the <exclusion> tag for each of the dependencies we want to exclude and placing all these exclusion tags inside the <exclusions> tag in pom.

How do I exclude a war file?

It is possible to include or exclude certain files from the WAR file, by using the <packagingIncludes> and <packagingExcludes> configuration parameters. They each take a comma-separated list of Ant file set patterns.

How do I exclude a specific version of a dependency in Maven?

Multiple transitive dependencies can be excluded by using the <exclusion> tag for each of the dependency you want to exclude and placing all these exclusion tags inside the <exclusions> tag in pom. xml. You will need to mention the group id and artifact id of the dependency you wish to exclude in the exclusion tag.


1 Answers

You can mark these dependencies as provided:

<dependency>   <groupId>xerces</groupId>   <artifactId>xerces</artifactId>   <version>2.4.0</version>   <scope>provided</scope> </dependency> 

This way the maven will add them to the compilation classpath, but will not package them. It is assumed they exist in your servlet container.

See more about maven scopes here under "scope"

Edit If you want to remove classes added via transitive dependencies you can exclude them from the dependency like this:

<dependency>         <groupId>org.springframework</groupId>         <artifactId>spring</artifactId>         <version>2.5.6</version>         <exclusions>                 <exclusion>                         <groupId>commons-logging</groupId>                         <artifactId>commons-logging</artifactId>                 </exclusion>         </exclusions> </dependency> 

(taken from this answer)

See more here

like image 92
David Rabinowitz Avatar answered Sep 30 '22 13:09

David Rabinowitz