前言
最近给公司服务写了一套方便客户开发的SDK,SDK开发完毕后想在测试服务程序通过maven引入本地jar包的方式进行功能测试,在引入jar包的过程中出现了SDK.jar无法被测试服务.jar打包进去,进儿对maven打包进行了一些研究。
下面进行了两类项目的两种常用打包方式的对比,对打成的jar包目录结果进行了梳理,最后附上maven引入本地jar包的解决方案。
非SpringBoot项目
工程目录
maven默认打包方式
默认打包方式即在pom文件中不设置打包方式,解压后的jar包目录结构如下:
SpringBoot插件方式
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
</plugins>
</build>
经过验证,仍然和默认的打包方式是一样的,解压后的jar包目录结果如下:
SpringBoot项目
工程目录
maven默认打包方式
SpringBoot插件方式
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
</plugins>
</build>
META-INF内容
BOOT-INF内容
SpringBoot启动jar包class文件
maven引入本地jar包
<!-- 本地jar包 -->
<dependency>
<groupId>com.enss.quequan</groupId>
<artifactId>quequan</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${pom.basedir}/conf/xxx-sdk-1.0.jar</systemPath>
</dependency>
<!-- 打包方式 -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
</plugins>
-
本地jar包
${pom.basedir}/conf/xxx-sdk-1.0.jarpom.basedir表示项目目录<scope>system</scope>必须是system
-
打包方式
SpringBoot项目使用spring-boot-maven-plugin打包方式