SpringBoot系列---【maven项目引入第三方jar包并打包发布】

一、问题

  项目中经常会碰到这样的问题,我们做的项目依赖别人打好的jar包,这种我们可以有两种途径解决,第一种是上传到私服,再从我们的项目去引入pom坐标,这种适合有私服账号或者自己会搭建私服的,成本有点高;第二种方法比较简单,就是直接在pom中打包时指定加载本项目目录下的jar包,下面就第二种方法展开说一下。

二、解决方案

  1.在项目根目录下新建lib文件夹,把需要的jar包放进去。

  2.在pom文件中新增坐标

<dependency>
     <groupId>com.demo</groupId>
     <artifactId>test</artifactId>
     <version>4.0.0</version>
     <scope>system</scope>
     <systemPath>${pom.basedir}/lib/test-4.0.0-SNAPSHOT.jar</systemPath>
</dependency>

  3.告诉maven将本地包打进jar包中

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <includeSystemScope>true</includeSystemScope>
    </configuration>
</plugin>

三、扩展

  maven打包可以控制是否需要将jar打入,通过scope标签,默认compile。

<dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-test</artifactId>
 <scope>test</scope>
</dependency>

 

posted on 2023-02-15 14:54  少年攻城狮  阅读(420)  评论(0)    收藏  举报

导航