如何导入第三方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>配置解决
相关推荐
Helix2502 天前
JDK 与 Maven 下载获取与构建配置实战:release 参数与 toolchains 编译版本对齐指南
java·jdk·maven·配置·toolchains·java构建·release参数
jaysee-sjc5 天前
【黑马点评】Day02:优惠券秒杀与分布式锁
java·分布式·nginx·spring·node.js·tomcat·maven
学无止境小袁同学7 天前
OpenAI Agents SDK 模板操作手册(可直接操作)
大模型·openai·agent·sdk·大模型应用
星落梦生7 天前
Maven高级(9)
java·maven
sxlishaobin14 天前
Maven Setting详解
java·学习·maven
Industio_触觉智能17 天前
RK3506 Buildroot系统目录地图-上|7个关键符号链接与构建产物全解析
嵌入式硬件·sdk·智能硬件·固件·瑞芯微·系统编译·rk3506
captain37620 天前
▲统一功能——DispatcherServlet源码分析
java·spring·java-ee·log4j·maven
没差c20 天前
winsw将jar、nginx等注册为Windows服务
windows·nginx·jar
todoitbo22 天前
启元机器人 Q1 SDK 接口实操:构建 aimdk_msgs 并用 ROS 2 本地 Mock 验证 Service 与 Topic
ai·机器人·二次开发·sdk·启元
雪芽蓝域zzs23 天前
第 1 章:IDEA 创建 SpringBoot3.5.16 Maven 项目
java·maven·intellij-idea