SpringBoot使用Maven打包异常-引入外部jar

3,040 阅读1分钟

导读


由于项目需要,在需要打包的时候,由于引入的外部jar在本地是可以使用的,但是当打包后启动时报错,找不到对应的类。

使用


1、引入外部jar包

项目中简历文件夹lib

可以在resultces包下简历一个lib文件夹,将jar包扔进去:

image.png

在配置文件中引用

  <dependency>
      <groupId>com.xx.xxx</groupId> //组织,随便命名
      <artifactId>***</artifactId> //包的名字,随便命名
      <version>1.1.2</version> //版本,随便命名
      <scope>system</scope>  //scope为system时,自动添加lib依赖包
      <systemPath>${basedir}/src/main/resources/lib/**.jar</systemPath> //路径,这里我jar在resources目录的lib文件夹下,也可以放在跟目标,路径按需修改
 </dependency>

2、项目打包

遇到问题

是由于项目打包时,不识别外部jar,又没有进行配置,继而导致出现问题。

解决方案

解决方式很简单,只需要在pom.xml里面配置下 includeSystemScope 就行。

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

END


chaohen:www.yuque.com/heioky

搞定~