美文网首页Java架构技术栈
SpringBoot使用Maven打包异常-引入外部jar

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

作者: 若丨寒 | 来源:发表于2020-06-19 16:40 被阅读0次
    SpringBoot使用Maven打包异常-引入外部jar

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

    使用

    1、引入外部jar包

    项目中建立文件夹lib

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

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

    在配置文件中引用

    <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>
    

    来源:
    https://www.tuicool.com/articles/mQbABrN

    相关文章

      网友评论

        本文标题:SpringBoot使用Maven打包异常-引入外部jar

        本文链接:https://www.haomeiwen.com/subject/gtqbxktx.html