Maven配置本地jar包依赖的几种方式

原文地址: https://www.ddmit.com/maven-install-local-jar/
在使用Maven管理依赖时,有时第三方Jar包必须得下载下来本地使用,这里总结maven配置本地依赖的几种方式。

方式一 安装jar文件包到本地仓库

mvn install:install-file -Dfile=D:\workspace\xf-cloud\lib\taobao-sdk-java-auto_1479188381469-20210727.jar -DgroupId=com.dingtalk -DartifactId=dingtalk-api-sdk -Dversion=1.0.0-SNAPSHOT -Dpackaging=jar -DgeneratePom=true 

安装过程如下:

C:\Users\Winbert>mvn install:install-file -Dfile=D:\workspace\xf-cloud\lib\taobao-sdk-java-auto_1479188381469-20210727.jar -DgroupId=com.dingtalk -DartifactId=dingtalk-api-sdk -Dversion=1.0.0-SNAPSHOT -Dpackaging=jar -DgeneratePom=true
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.4:install-file (default-cli) @ standalone-pom ---
[INFO] Installing D:\workspace\xf-cloud\lib\taobao-sdk-java-auto_1479188381469-20210727.jar to D:\ProgramData\maven-repository\com\dingtalk\dingtalk-api-sdk\1.0.0-SNAPSHOT\dingtalk-api-sdk-1.0.0-SNAPSHOT.jar
[INFO] Installing C:\Users\Winbert\AppData\Local\Temp\mvninstall6463484044721168508.pom to D:\ProgramData\maven-repository\com\dingtalk\dingtalk-api-sdk\1.0.0-SNAPSHOT\dingtalk-api-sdk-1.0.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.512 s
[INFO] Finished at: 2021-08-09T00:12:30+08:00
[INFO] ------------------------------------------------------------------------

方式二 配置pom文件

    <dependency>
        <groupId>com.dingtalk</groupId>
        <artifactId>dingtalk-api-sdk</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <scope>system</scope>
        <systemPath>${pom.basedir}/lib/taobao-sdk-java-auto_1479188381469-20210727.jar</systemPath>
    </dependency>

配置插件,打包时将本地jar文件打入:

 <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <includeSystemScope>true</includeSystemScope>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>repackage</goal>
            </goals>
        </execution>
    </executions>
</plugin>

maven-install-local-jar.jpg

Reference

1.Maven 依赖外部jar包 (以钉钉为例)

赞(1)
未经允许禁止转载:优米格 » Maven配置本地jar包依赖的几种方式

评论 抢沙发

合作&反馈&投稿

商务合作、问题反馈、投稿,欢迎联系

广告合作侵权联系