SpringBoot项目使用外部jar包,打包运行后报错class未找到

SpringBoot项目使用外部jar包,打包运行后报错class未找到


打包方式:

1. 先将jar发布到本地maven仓库

mvn install:install-file -DgroupId=com.labi -DartifactId=pub -Dversion=1.0 -Dpackaging=jar -Dfile=pub-1.0-SNAPSHOT.jar

-DgroupId:表示jar对应的groupId
<groupId>com.labi</groupId>


-DartifactId: 表示jar对应的artifactId
<artifactId>pub</artifactId>


-Dversion: 表示jar对应的 version
<version>1.0</version>
2. 在pom文件中中添加依赖

本项目中外部jar包同一放在resources的lib文件夹下

<dependency>
    <groupId>com.labi</groupId>
    <artifactId>pub</artifactId>
    <version>1.0-SNAPSHOT</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/src/main/resources/lib/pub-1.0-SNAPSHOT.jar</systemPath>
</dependency>
3. 本项目pom文件,配置打包时把外部jar也打进来
// 主要为以下两行
<includeSystemScope>true</includeSystemScope>
<executable>true</executable>



<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <version>2.3.7.RELEASE</version>
    <configuration>
        <mainClass>com.center.CenterApplication</mainClass>
        <includeSystemScope>true</includeSystemScope>
        <executable>true</executable>
    </configuration>
    <executions>
        <execution>
            <id>repackage</id>
            <goals>
                <goal>repackage</goal>
            </goals>
        </execution>
    </executions>
</plugin>
打包之前先clean,再package

打包命令:mvn clean package -Dmaven.test.skip=true

打完包之后项目中会自动生成一个target文件夹,其中有个项目名.jar包就是我们打成的包

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值