Search code examples
mavenmaven-war-plugin

Exclude all the jar's from webapp/WEB-INF/lib


I have the third party jar's in my WEB project placed at /src/main/webapp/WEB-INF/lib/

I have mentioned the dependency for all the required JAR's in the pom.xml. Now, Since the dependencies are defined in POM, the JAR's will be automatically packed in the lib folder.

  • I want to exclude all the JAR's in the lib.
  • The Dependency JAR's should be packaged inside the lib while building the WAR

I CANT DELETE THE LIB FROM WEB-INF BECAUSE ITS USED IN LOCAL DEVELOPMENT

This is what I've tried so far:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-war-plugin</artifactId>
  <configuration>
    <packagingExcludes>META-INF/context.xml</packagingExcludes>
    <webResources>
      <resource>
        <directory>src/main/webapp/WEB-INF/lib</directory>
        <excludes>
          <exclude>**/**</exclude>
        </excludes>
      </resource>
    </webResources>
  </configuration>
</plugin>

Any Idea?


Solution

  • Try this:

    <configuration>
        <warSourceExcludes>WEB-INF/lib/*.jar</warSourceExcludes>
        ....
    </configuration>
    

    However, I do agree with Jarrod that it is bad practice to store your jars in WEB-INF/lib 'manually'. I used this before to avoid that jars coming as a dependency got packaged to be able to repackage it afterwards.