How to Include specific jars in WAR, WEB-INF/lib directory with maven
You just have to put your 3 specific libraries as dependencies of the project and maven will put it on WEB-INF/lib during package phase
Update:
To exclude JAR comming from dependencies you have to use this kind of syntax
<dependency>
<groupId>sample.ProjectA</groupId>
<artifactId>Project-A</artifactId>
<version>1.0</version>
<exclusions>
<exclusion> <!-- declare the exclusion here -->
<groupId>sample.ProjectB</groupId>
<artifactId>Project-B</artifactId>
</exclusion>
</exclusions>
</dependency>
And to exclude all sub dependencies (maven 3 only):
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
Update 2
with maven-war-plugin you should add WEB-INF/classes/** to packagingIncludes
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<warSourceDirectory>src/main/webapp</warSourceDirectory>
<packagingIncludes>WEB-INF/lib/frm-fl*.jar,WEB-INF/lib/frm-bean*.jar,WEB-INF/lib/frm-facade-${ffm.fpi.version}.jar,WEB-INF/classes/**></packagingIncludes>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
naamadheya
Updated on September 20, 2020Comments
-
naamadheya over 3 years
This is my pom.xml, trying to create a WAR file with specific 3 libraries in WEB-INF/lib directory.
I include them in
<packagingIncludes>
tag and the they are packaged in lib dir, but all.class
files are ignored.I cannot use
<packagingExcludes>
because the dependent project has many 3rd party jars and out of my control.what is wrong here or is there a way i can ignore all jars except 3 specific jars?
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>1.0</modelVersion> <parent> <groupId>frmId</groupId> <artifactId>frm</artifactId> <version>1.5.9</version> </parent> <artifactId>frmw</artifactId> <packaging>war</packaging> <build> <sourceDirectory>src/main/java</sourceDirectory> <resources> <resource> <directory>src/main/resources</directory> <excludes> <exclude>**/*.java</exclude> </excludes> </resource> </resources> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.2</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> <plugin> <artifactId>maven-war-plugin</artifactId> <version>2.3</version> <configuration> <warSourceDirectory>src/main/webapp</warSourceDirectory> <packagingIncludes>WEB-INF/lib/frm-fl*.jar,WEB-INF/lib/frm-bean*.jar,WEB-INF/lib/frm-facade-${ffm.fpi.version}.jar</packagingIncludes> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin> <plugin> <groupId>com.fortify.ps.maven.plugin</groupId> <artifactId>sca-maven-plugin</artifactId> <version>${maven-sca-plugin.version}</version> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>com.fi.ps</groupId> <artifactId>frmc-fl</artifactId> <version>${project.version}</version> </dependency> </dependencies>
-
naamadheya over 8 yearsI tried that. As I said the dependencies have internal huge list dependencies and all those jars would come into lib folder. Which i do not want.
-
fabballe over 8 yearsI edit my answer to explain how to exclude sub dependencies
-
naamadheya over 8 yearsIf I ignore sub dependencies then I have compilation issues.
-
fabballe over 8 yearsIf you need some jar during the compilation but not on the final war you have to use <scope>provided</scope> on the jar
-
naamadheya over 8 yearsI donot have the control of those jars. It varies from the version of dependent project i use and it is huge list to use <scope>. Hope I am making sense.
-
fabballe over 8 yearsOk I understand. I can't try but I think if you should add WEB-INF/classes/* to packagingIncludes in order to have all class file. I update my answer
-
naamadheya over 8 yearsThanks. But WEB-INF/classes/* did not help. Just the folder was added not the .class files.
-
fabballe over 8 yearsLet us continue this discussion in chat.
-
fabballe over 8 yearsAnswer is in the chat. I updated my answer. Can you mark the answer as accep please ?