maven依赖为 scope system不能打入部署包问题解决

文章讲述了在Springboot项目开发中,通过maven引入本地第三方jar包,在IDEA中运行正常,但打包成jar运行时出现缺少jar包类的错误。问题在于spring-boot-maven-plugin插件在打包时不会包含系统路径下的jar。解决方案是将依赖的外部jar包复制到主入口模块并添加相应pom依赖,确保打包时一并包含。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  1. 问题描述

springboot项目开发中maven引入本地第三方jar包,在idea中运行正常。部署打成jar包后,运行报错缺少引入的jar包类

  1. 项目说明:

项目基于springboot分模块开发,在业务模块引入第三方jar

<dependency>
        <groupId>com.zyb</groupId>
        <artifactId>xxx-xx</artifactId>
        <version>1.0</version>
        <scope>system</scope>
        <systemPath>${project.basedir}/src/main/resources/libs/xxx-xx-1.0.jar</systemPath>
</dependency>

在springboot主入口模块的pom中,maven-plugin插件配置如下

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <version>2.1.1.RELEASE</version>
    <configuration>
        <includeSystemScope>true</includeSystemScope> <!-- 引入外部jar包 -->
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>repackage</goal>
            </goals>
        </execution>
    </executions>
</plugin>

左看右看 <includeSystemScope>true</includeSystemScope>也引入了,

但项目打包部署jar运行就显示缺少外部jar中的类

  1. 原因及解决方法

springboot的maven打包插件,只会扫描当前模块下的路径,导致并不会把其他模块项目路径下的外 部jar进行打包,

将引入外部jar包的pom依赖,在主入口模块的pom中也引入一份,同时将外部的jar放到相对应的指定目录下即可解决

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值