如何导入第三方sdk | 引入第三方jar 包

    • [0. 背景](#0. 背景)
    • [1. 上传私有仓库](#1. 上传私有仓库)
    • [2. 使用本地文件系统](#2. 使用本地文件系统)

0. 背景

对接一些第三方功能,会拿到第三方的sdk,也就是jar包,如何导入呢

1. 上传私有仓库

  • 最好的方式就是将第三方jar包,上传到私有的仓库,这样直接正常在pom引用即可
  • 如果只是本地开发,可以将本地jar加载到本地mvn仓库,执行如下命令
    • mvn install:install-file -Dfile=./xxx-1.0.0.jar -DgroupId=cn.xxx.xxx -DartifactId=xxx -Dversion=1.0.0 -Dpackaging=jar
    • 即可引入对应groupId、artifactId、version的依赖
    • 如果要部署环境,则不行,但可以使用本地文件系统来处理

2. 使用本地文件系统

  • 在pom的<dependency>中,
    • 使用<scope>system</scope>
      • 表示依赖来自本地文件系统,而非 Maven 仓库
    • systemPath指定本地jar包路径,建议放在项目中,如<systemPath>${project.basedir}/lib/A.jar</systemPath>
xml 复制代码
<dependency>
    <groupId>com.example</groupId>  <!-- 自定义组ID -->
    <artifactId>A</artifactId>      <!-- 自定义构件ID -->
    <version>1.0.0</version>        <!-- 自定义版本号 -->
    <scope>system</scope>           <!-- 指定作用域为 system -->
    <systemPath>${project.basedir}/lib/A.jar</systemPath>  <!-- 指定本地路径 -->
</dependency>

 <!--指定使用maven打包-->
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>${springBoot.version}</version>

                <configuration>
                    <mainClass>com.example.MybatisExampleApplication</mainClass>
                    <!--设置为true,以便把本地的system的jar也包括进来-->
                    <includeSystemScope>true</includeSystemScope>
                </configuration>

                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
    </build>
  • groupId、artifactId、version都是自定义的,随便都行
  • 需要注意,system作于的依赖作用域的依赖不会随项目打包,可以通过mvn插件spring-boot-maven-plugin<includeSystemScope>true</includeSystemScope>配置解决
相关推荐
柒.梧.21 小时前
Maven构建工具全解析
junit·maven
YANshangqian1 天前
Electerm(桌面终端模拟软件)
eclipse·maven
一点晖光1 天前
maven推送项目到harhor私有仓库
java·maven
Gu_yyqx2 天前
Maven进阶
java·maven
waper972 天前
nohup java -jar启动jar包错报错 地址已在使用
java·开发语言·jar
diudiu96282 天前
Maven配置阿里云镜像
java·spring·阿里云·servlet·eclipse·tomcat·maven
计算机毕设指导62 天前
基于微信小程序的鸟博士系统【源码文末联系】
java·spring boot·mysql·微信小程序·小程序·tomcat·maven
Ahtacca2 天前
Maven 入门:项目管理与依赖管理的核心玩法
java·maven
信仰JR2 天前
Linux系统安装Maven私服Nexus3.X
linux·运维·maven
CryptoRzz2 天前
日本股票 API 对接实战指南(实时行情与 IPO 专题)
java·开发语言·python·区块链·maven