How to exclude jars generated by maven war plugin?

About exclusion of transitive dependencies, i think don't work with transtive of transitive dependecies, and i think this could be the case.

For example, add dependency of hibernate-core -> dom4j -> xml-apis if add exclude of xml-apis near your hibernate-core, still add xml-apis...


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


I had no possibility to modify depending war file. I needed to avoid some old jar file from lib. This snippet of POM.xml configuration works well for me. I use Maven 2.2.

<build>
    <plugins>
        <!-- put aside some unwanted jars from war...-->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.1.1</version>
            <configuration>
                <overlays>
                    <overlay>
                        <groupId>com.company.app</groupId>
                        <artifactId>web_app</artifactId>
                        <excludes>
                            <exclude>WEB-INF/lib/json-lib-2.2.2-jdk13.jar</exclude>                                
                        </excludes>
                    </overlay>
                </overlays>
            </configuration>
        </plugin>
        ....

I fixed it.

Rereading the reference with a bit more care, I discovered that the element packagingExcludes should be warSourceExcludes.

Tags:

Java

Maven 2