spring boot 项目打成jar包并被其他项目引用
程序员文章站
2024-02-02 21:40:04
...
spring boot 项目打成jar包并被其他项目引用
spring boot 项目打成jar包
- 剔除要引入的springboot项目中不需要的文件:如Application和ApplicationTests等
2.打包
不能使用springboot项目自带的打包插件进行打包:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
而应当使用传统项目的maven打包:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source> <!--指明源码用的Jdk版本-->
<target>1.8</target> <!--指明打包后的Jdk版本-->
</configuration>
</plugin>
</plugins>
</build>
因为springboot-maven-plugin打包的第一级目录为Boot-INF,无法引用.
并install到本地maven库中:
mvn clean install -Dmaven.test.skip=true
3.springboot项目中引用jar包
pom.xml相关内容:
<dependency>
<groupId>com.cmstk_api</groupId>
<artifactId>sdk</artifactId>
<scope>system</scope>
<version>1.0</version>
<systemPath>${project.basedir}/lib/cmstk_api.jar</systemPath>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>lib</directory>
<targetPath>BOOT-INF/lib/</targetPath>
<includes>
<include>**/*.jar</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<targetPath>BOOT-INF/classes/</targetPath>
</resource>
</resources>
</build>
参考链接1:https://blog.csdn.net/fhf2424045058/article/details/84023549?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.edu_weight&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.edu_weight
参考链接2:https://blog.csdn.net/lovexiaotaozi/article/details/83576904