How to include system dependencies in war built using maven

maven include system scope jars in jar
maven include system scope jars in war
maven include jars in web-inf/lib
maven include external jar in war
maven include dependencies in jar
how to include jar in war file
spring-boot-maven-plugin include system scope
maven shade plugin include system scope dependencies

I've searched on internet for quite some time and I'm unable to figure out how to configure the maven-war plugin or something alike so that the system dependencies are included in the built-war (WEB-INF/lib folder)

I use the maven dependency plugin in case of a jar-build as :

<plugin>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <phase>install</phase>
            <goals>
                <goal>copy-dependencies</goal>
            </goals>
            <configuration>
                <outputDirectory>${project.build.directory}/lib</outputDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>

but I'm unable to understand what is to be done in case of a war build. I've tried using the maven-war plugin, but it's not including system-dependencies in the build.

[UPDATE]

I'm having depedencies of type :

<dependency>
    <groupId>LoginRadius</groupId>
    <artifactId>LoginRadius</artifactId>
    <scope>system</scope>
    <version>1.0</version>
    <systemPath>${basedir}\lib\LoginRadius-1.0.jar</systemPath>
</dependency>

in my POM and these dependencies are not included in WEB-INF/lib when the war is build.

Let me try to summarise the options I tried :

<packagingIncludes>${java.home}/lib/jfxrt.jar</packagingIncludes>

This doesn't work! Also, only having the jar name, excludes everything else, so if you are willing to try then try

<packagingIncludes>${java.home}/lib/jfxrt.jar,**/*</packagingIncludes>

Jatin's answer seemed a bit complex and I tried going through the POM again & again to figure out where exactly were the system jars mentioned to be included in WEB-INF POM.

Anyways, I ended up using this solution, which wasn't working at first but after some time and some corrections worked :

I installed the jar in my local repository using the below command :

mvn install:install-file -Dfile="C:\Users\hp\Documents\NetBeansProjects\TwitterAndLoginRadiusMaven\lib\LoginRadius-1.0.jar" -DgroupId=LoginRadius -DartifactId=LoginRadius -Dversion=1.0 -Dpackaging=jar`

After running the above command, I changed the dependency in POM to

<dependency>
   <groupId>LoginRadius</groupId>
   <artifactId>LoginRadius</artifactId>
   <!--<scope>system</scope>-->
   <version>1.0</version>
   <!--<systemPath>${basedir}\lib\LoginRadius-1.0.jar</systemPath>-->
</dependency>

NOTE - See I've commented the system scope & systemPath.

Building the war now, includes this LoginRadius-1.0.jar in WEB-INF/lib

java, Let me try to summarise the options I tried : <packagingIncludes>${java.home}/lib​/jfxrt.jar</packagingIncludes>. This doesn't work! Also, only  I want to include various maven dependencies (.jar files) in my .war depolyment. I want these jars to end up in the war file under myApp/WEB-INF/lib. Currently I can build the project using the traditional eclipse method: from the Tomcat option | Deploy to war file path. Eclipse is apparently building against my .m2 repository.

If by chance you can't install the third party library to your local repository, due to some silly naming/packaging checks by the third party, you can still add your system scoped dependencies to your final package at build time (at least if you are building a webapp) using the maven-war-plugin where you would need to create a configuration like this.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.2.0</version>
    <configuration>
        <failOnMissingWebXml>true</failOnMissingWebXml>
        <webResources>
            <resource>
               <directory>path/to/lib/in/project</directory>
               <targetPath>WEB-INF/lib</targetPath>
            </resource>
        </webResources>
    </configuration>
</plugin>

Not sure but I believe that the library must be somewhere local to the project's base directory. I tend to create a directory under src/main/ called lib to hold these sorts of 3rd party libs. During build process they are placed in the correct directory and added to the war file.

Apache Maven WAR Plugin – Including and Excluding Files From , Built by Maven. Including and Excluding Files From the WAR. It is possible to include or exclude certain files from the WAR file, by using In this example we want to exclude any commons-logging and log4j JARs, but we do  If by chance you can't install the third party library to your local repository, due to some silly naming/packaging checks by the third party, you can still add your system scoped dependencies to your final package at build time (at least if you are building a webapp) using the maven-war-plugin where you would need to create a configuration like this.

If you meant as jar dependencies, then below is a sample pom.xml which takes are needed files and generates a war file:

 <build>
        <defaultGoal>install</defaultGoal>
        <sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
        <testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>
        <outputDirectory>${project.basedir}/target/classes</outputDirectory>
        <testOutputDirectory>${project.basedir}/target/test-classes</testOutputDirectory>
        <resources>
            <resource>
                <directory>${project.basedir}/src/main/resources</directory>
            </resource>
        </resources>
        <testResources>
            <testResource>
                <directory>${project.basedir}/src/test/resources</directory>
            </testResource>
        </testResources>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>2.0.2</version>
                    <configuration>
                        <source>1.5</source>
                        <target>1.5</target>
                        <debug>true</debug>
                    </configuration>
                </plugin>
                <plugin>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.4</version>
                    <configuration>
                        <includeEmptyDirs>true</includeEmptyDirs>
                        <webResources>
                            <resource>
                                <directory>ui</directory>
                                <targetPath></targetPath>
                                <includes>
                                    <include>**</include>
                                </includes>
                            </resource>
                            <resource>
                                <directory>lib</directory>
                                <targetPath>WEB-INF</targetPath>
                                <includes>
                                    <include>**/*.xml</include>
                                    <include>**/log4j.properties</include>
                                </includes>
                            </resource>
//edited below
                            <resource>
                               <directory>lib</directory>
                               <targetPath>WEB_INF/lib</targetPath>
                               <includes>
                                    <include>**/*.jar</include>
                               </includes>
                            </resource>
                        </webResources>
                        <webXml>${project.basedir}/WEB-INF/web.xml</webXml>
                    </configuration>
                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-source-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>attach-sources</id>
                            <goals>
                                <goal>jar</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

Maven dependency scopes with relation to WAR file packaging and , I've written articles about building web services using Maven in the past as cover how Maven's dependency mechanism relates to WAR file packaging, For the provided, test and system scopes the WEB-INF/lib directory will not contain is not created at all since there aren't any other JARs are inside it. If you don’t have Maven repository server like Archiva or Nexus, you may need to include those libs which are not public on the internet in your Maven project and specifiy the dependency scope as system in the pom.xml. The following example includes the eureka-0.0.1.jar which is located in the folder called external on project root. <dependency> <groupId>ykyuen.info</groupId> <artifactId>eureka</artifactId> <version>0.0.1</version> <scope>system</scope> <systemPath>${project.basedir

Based on your initial POM, I would suggest to send them directly to the WEB-INF/lib directory

                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}/${project.artifactId}-${project.version}/WEB-INF/lib</outputDirectory>
                    </configuration>

How to include maven dependencies in war file (WEB-INF/lib , I want these jars to end up in the war file under myApp/WEB-INF/lib. Currently I can build the project using the traditional eclipse method: from the  maven-dependency-plugin: The dependency plugin provides the capability to manipulate artifacts. It can copy and/or unpack artifacts from local or remote repositories to a specified location. maven-jar-plugin: This plugin provides the capability to build and sign jars. Here is a complete pom.xml file. Mainly you would be interested in <build> tag.

You can configure the war plugin to have all or some jar included or excluded as per your need as mentioned below. Simple & works

           <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <webResources>
                        <resource>
                            <directory>${project.basedir}\lib</directory>
                            <targetPath>WEB-INF/lib</targetPath>
                            <filtering>false</filtering>
                            <includes>
                                <include>**/*.jar</include>
                            </includes>
                            <excludes>
                                <include>**/javax.servlet-api-3.1.0.jar</include>
                            </excludes>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>

Maven – Include system scope dependency in maven-assembly , Maven – Package the jar file with dependencies. Please note A workaround is instead of using system scope, we could make use of the maven-install-plugin to in install the external jars to the machine local Maven repository before the build. So you Maven - Dependency on jar/war packageIn "Maven". Including and Excluding Files From the WAR. 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. You can use wildcards such as ** to indicate multiple directories and * to indicate an optional part of a file or directory name.

How to include system dependencies in war built using maven, I've searched on internet for quite some time and I'm unable to figure out how to configure the maven-war plugi. Now, you can control which dependencies are included in WEB-INF/lib and in the manifest classpath by following these examples. Maven will follow the transitive dependency tree until it gets to artifacts scoped as "provided". Note: No way is shown how to include a dependency in WEB-INF/lib but not in the manifest classpath.

Maven Dependency Scopes, It provides six scopes i.e. compile, provided, runtime, test, system, and import. with maven dependency scope runtime are not needed to build, but are part of the systemPath >${basedir}\war\WEB-INF\lib\extDependency.jar</ systemPath >. Maven dependency transitivity resolution. When you include a maven dependency and it has it’s own other dependencies (i.e. transitive dependencies) then you may want to be clear about the scope of these transitive dependencies as well. Let’s understand about maven transitive dependencies with a simple table.

Getting Started, This guide walks you through using Maven to build a simple Java project. structure; for example, with mkdir -p src/main/java/hello on *nix systems: to the project's library artifact (for example, the name of its JAR or WAR file). the local dependency repository, ready for another project to reference it as a dependency​. Dependencies with the scope system are always available and are not looked up in repository. They are usually used to tell Maven about dependencies which are provided by the JDK or the VM. Thus, system dependencies are especially useful for resolving dependencies on artifacts which are now provided by the JDK,

Comments
  • What exactly do you mean by system dependencies?
  • I have included 3 jars in system scope in the project and I want them to be included in the WEB-INF/lib folder along with other dependencies in the final built war
  • possible duplicate of Maven 2 assembly with dependencies: jar under scope "system" not included
  • See also stackoverflow.com/questions/33799773/…
  • So, the Maven "fundamentalists" don't care that you now cannot have a 2 step build consisting of (ONLY) the steps: (1) Fetch from source control; (2) type a single build command (whether it's mvn, ant, make or build.{sh|bat}). This "solution", which I'm not blaming you for, it just seems to be part of Maven, now has a dependency that you either run this magic "install" incantation to put stuff in ~/.m2/ cache directory, OR, possess a work-group "Nexus" type cache in front of Maven Central which you also have permission to "deploy" things into.
  • Maven's dependency management model works great when you are pulling in Apache and Spring libraries, but not so much when you have libraries (jars) from vendors who do not want their stuff in Maven Central :-(
  • I agree. The need to put everything into repositories is a real inadequacy in Maven, since there actually could be reasons why someone may not want to do so (like having a single small jar that isn't worth creating a whole repo for). This really needs to be corrected. Meanwhile, I am switching to gradle...
  • This would be fine so long as the third party library allows the jar to be renamed. Some libraries from SAP do not allow the renaming that maven uses. So I have to continue using a dependency with a system scope.
  • if i do this. it is necessary to include the libraries as dependencies also? or do i have to remove the system dependencies?
  • @elbraulio I'm guessing you are asking if you need to specifically add includes for the normal dependencies. The standard dependencies (compile in scope) are handled normally, this should only target the ones that are system in scope.