手记

Maven打包时添加外部jar

方法一

1.安装本地jar包到本地maven仓库

mvn install:install-file 
    -Dfile=alipay-sdk-java-3.0.0.jar  
    -DgroupId=com.aliyun 
    -DartifactId=alipay-sdk-java-3.0.0 
    -Dversion=3.0.0 
    -Dpackaging=jar

2.普通方式导入jar包

<dependency>
   <groupId>com.aliyun</groupId>
   <artifactId>alipay-sdk-java-3.0.0</artifactId>
   <version>3.0.0</version></dependency>

方法二

1、首先在工程目录下创建lib文件夹用来存放本都引入jar包。

image.png

2、修改pom.xml文件引入本地jar

配置Jar的dependency,包括groupId,artifactId,version三个属性,同时还要包含scope和systemPath属性,分别指定Jar包来源于本地文件,和本地文件的所在路径。

<dependency>
    <groupId>com</groupId>
    <artifactId>wade-trace</artifactId>
    <version>5.5</version>
    <scope>system</scope>
    <systemPath>${basedir}/lib/wade-trace.jar</systemPath></dependency><dependency>
    <groupId>com</groupId>
    <artifactId>wade-tool</artifactId>
    <version>5.5</version>
    <scope>system</scope>
    <systemPath>${basedir}/lib/wade-tool.jar</systemPath></dependency>

3.添加maven-war-plugin插件

 <!-- 将外部jar一起打包成war --><plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
        <webResources>
            <resource>
                <directory>${project.basedir}/lib</directory>
                <targetPath>WEB-INF/lib</targetPath>
                <includes>
                    <include>**/*.jar</include>
                </includes>
            </resource>
        </webResources>
    </configuration></plugin>



作者:年少时难免轻狂Ho
链接:https://www.jianshu.com/p/7002b93c0742


0人推荐
随时随地看视频
慕课网APP