Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

packagingExcludes not working in maven war plugin

I've following in my pom.xml

...
   <groupId>my.org.name</groupId>
    <artifactId>webservices-webapp</artifactId>
    <packaging>war</packaging>
    <name>Webapp</name>
<dependencies>
...
</dependecies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <attachClasses>true</attachClasses>
                    <packagingExcludes>
                        WEB-INF/lib/avalon-*.jar,
                        WEB-INF/lib/geronimo-*.jar,
                        WEB-INF/lib/aopalliance-*.jar,
                        WEB-INF/lib/common-*.jar,
                        WEB-INF/lib/core-cryptor-*.jar,
                        WEB-INF/lib/logging-*.jar,
                        WEB-INF/lib/rm-security-*.jar,
                        WEB-INF/lib/security-context-shared-*.jar,
                        WEB-INF/lib/session-management-*.jar,
                        WEB-INF/lib/jax*.jar,
                        WEB-INF/lib/joda-time-*.jar,
                        WEB-INF/lib/opensaml-*.jar,WEB-INF/lib/spring-security-core-*.jar,
                        WEB-INF/lib/xmlsec-*.jar,WEB-INF/lib/xmltooling-*.jar,
                        WEB-INF/lib/stax-api-*.jar,
                        WEB-INF/lib/servlet-api-*.jar,WEB-INF/lib/axis-saaj-*.jar,WEB-INF/lib/axis-jaxrpc-*.jar,
                        %regex[WEB-INF/lib/spring-(?!web).*.jar]
                    </packagingExcludes>
                    <archive>
                        <manifestEntries>
                            <DisableIBMJAXWSEngine>true</DisableIBMJAXWSEngine>
                        </manifestEntries>
                    </archive>
                    <webResources>
                        <resource>
                            <directory>src/main/java</directory>
                            <targetPath>WEB-INF/classes</targetPath>
                            <includes>
                                <include>**/*.xml</include>
                            </includes>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>
        </plugins>
        <finalName>${project.artifactId}</finalName>
    </build>

Now when I do mvn clean install. I get all jars in the target/webapp/WEB-INF/lib actually I shouldn't get the jars matching excluded patters like avalon-.jar,geronimo-.jar,aopalliance-.jar,common-.jar etc..

Why are these excluded jars coming in WEB_INF/lib??

like image 928
Akshay Hiremath Avatar asked Apr 15 '16 10:04

Akshay Hiremath


People also ask

What is packagingExcludes?

packagingExcludes: The comma separated list of tokens to exclude from the WAR before packaging. With packagingExcludes, the tokens are completely excluded from the final war file. With warSourceExcludes, the tokens are just ignored when copying the war directory into the war file.

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. xml.


2 Answers

packagingExcludes applies to war archive. It has no impact to "exploded" war.

Reference: https://github.com/apache/maven-plugins/blob/maven-war-plugin-2.6/src/main/java/org/apache/maven/plugin/war/packaging/WarProjectPackagingTask.java#L109

(handleArtifacts( context ) is called regardless of packagingExcludes

like image 156
michaldo Avatar answered Oct 02 '22 11:10

michaldo


packagingExcludes exclude jar files.

But if application is spring boot, in the repackaging phase, it puts all the jars back in new package and renames old package to .war.original .

like image 45
Ali Avatar answered Oct 02 '22 11:10

Ali