javaeclipsemaven

How to include system dependencies in a WAR file built using Maven


I've searched on the 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.

I'm having dependencies 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 file, and these dependencies are not included in WEB-INF/lib when the WAR file is build.


Solution

  • 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 file 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 file again and again to figure out where exactly were the system JAR files mentioned to be included in WEB-INF POM.

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

    I installed the JAR file 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 and systemPath.

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