致访客
感谢各位一年多的陪伴,因内容调整,本站将于近日迁移到新域名并不再更新主要内容。
特此通知。
感谢各位一年多的陪伴,因内容调整,本站将于近日迁移到新域名并不再更新主要内容。
特此通知。
概述
SpringBoot开发时需要引入第三方jar包,这些包不存在于Maven仓库,所以有两种解决方式:
- jar包部署在maven私服中
- 打包jar到项目中
打包jar包比较简单,但是打包war的时候就有坑了,试了网上很多方法,发现项目打包war包后会出现找不到第三方jar包中的Class的问题。
打jar包引入三方依赖
src/main/resources
建立lib
目录,拷贝第三方jar包进去
之后在pom文件添加依赖
<dependency>
<groupId>随便起,例如com.example</groupId>
<artifactId>随便起,例如myexample</artifactId>
<version>版本随意,例如1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/你的jar包名称.jar</systemPath>
</dependency>
pom添加插件
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
之后再使用mvn clean package
即可整合进去
打war包引入三方依赖(webapp方式)
打war包时引入三方依赖就有坑了,webapp方式打包方法如下:
拷贝jar包到src/main/webapp/WEB-INF/
下的lib
目录下(没有就创建),然后将第三方jar包扔进去;接下来pom文件添加依赖
<dependency>
<groupId>随便起,例如com.example</groupId>
<artifactId>随便起,例如myexample</artifactId>
<version>版本随意,例如1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/你的jar包名称.jar</systemPath>
</dependency>
pom添加插件
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
打war包引入三方依赖(resources方式)
这种方式可以不创建webapp目录,而是放在resources下
第一步引入依赖
<dependency>
<groupId>随便起,例如com.example</groupId>
<artifactId>随便起,例如myexample</artifactId>
<version>版本随意,例如1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/你的jar包名称.jar</systemPath>
</dependency>
pom添加插件,这里是要把jar添加到webResources里,才能打包进去
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<resource>
<directory>src/main/resources/lib</directory>
<targetPath>WEB-INF/lib/</targetPath>
<includes>
<include>**/*.jar</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
其他打包方式
还有spring-boot-maven-plugin打包结构、maven-war-plugin打包结构等等这里就不一一列出了,可以查看参考链接
参考链接
- SpringBoot引入第三方jar包或本地jar包的处理方式:https://blog.csdn.net/J080624/article/details/81505937