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 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}libLoginRadius-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 :

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

mvn install:install-file -Dfile="C:UsershpDocumentsNetBeansProjectsTwitterAndLoginRadiusMavenlibLoginRadius-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}libLoginRadius-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


如果你的意思是jar依赖,那么下面是一个示例pom.xml,它是需要的文件并生成一个war文件:

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

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.

链接地址: http://www.djcxy.com/p/29654.html

上一篇: Mavenize您的项目jar文件或将它们放入WEB是最好的

下一篇: 如何在使用maven构建的war中包含系统依赖关系