当前位置: 首页 > article >正文

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

    • 0. 背景
    • 1. 上传私有仓库
    • 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>
<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>配置解决

http://www.kler.cn/a/536465.html

相关文章:

  • 4.PPT:日月潭景点介绍【18】
  • Windows Docker笔记-制作、加载镜像
  • 使用git clone一个指定文件或者目录
  • EGO-Planner文章解读(一)——论文原理和算法实现
  • 【LeetCode】152、乘积最大子数组
  • PostgreSql 函数异常处理
  • 项目实战 —— HTTP服务器设计与实现
  • FocusAny v0.6.0 MacOS和Linux安装优化,独立窗口显示优化
  • mysql-connector-java 和 mysql-connector-j的区别
  • C语言-预处理
  • BpmnJS源码篇1:Injector 依赖注入模式的实现
  • 一、lambda表达式处理stream操作
  • 换电脑了如何快速导出vscode里的插件
  • 【C/C++算法】从浅到深学习---双指针算法(图文兼备 + 源码详解)
  • 低成本训练的突破与争议:DeepSeek R1模型的新进展
  • (2024|Nature Medicine,生物医学 AI,BiomedGPT)面向多种生物医学任务的通用视觉-语言基础模型
  • 3.Python分支和循环:if判断语句、运算符、if-else语句、while循环、for循环、break、continue
  • nuxt3中报错: `setInterval` should not be used on the server.
  • 不定参数.
  • 2、k8s的cni网络插件和基本操作命令
  • 极客说|利用 Azure AI Agent Service 创建自定义 VS Code Chat participant
  • Codeforces Round 995 (Div. 3)
  • 使用VSCode接入DeepSeek探索
  • 封装descriptions组件,描述,灵活
  • Ansys Maxwell:磁耦合器 - 扭矩与角度分析
  • 800G光模块:引领未来数据中心与网络通信的新引擎