解决第三方jar包引入,打包后运行找不到类

<dependency>
    <groupId>xxxxx</groupId>
    <artifactId>xxxxx</artifactId>
    <version>XXXXXX</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/libs/xxxxx.jar</systemPath>
</dependency>

在项目中如上所示,将第三方jar包放到项目资源目录下,引入jar包使用。

本地运行一切OK,但是打包后部署到服务器后,执行相关第三方jar包的方法,会报错:

 nested exception is java.lang.NoClassDefFoundError,找不到对应的类。

解决方法:

在项目的pom文件中引入下列配置项,其中

<includeSystemScope>true</includeSystemScope>标签是关键。引入了以后重新打包就能解决问题了。

注意:<version>一定要跟springboot的版本一致。

    <build>
        <!-- 设置构建的 jar 包名 -->
        <finalName>${project.artifactId}</finalName>
        <plugins>
            <!-- 打包 -->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>${spring.boot.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal> <!-- 将引入的 jar 打入其中 -->
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <includeSystemScope>true</includeSystemScope>
                </configuration>
            </plugin>
        </plugins>
    </build>

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值