欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

在Spring Boot项目中添加外部JAR包后,部署运行时遇到找不到相关类的错误问题

最编程 2024-07-30 21:16:36
...

今天遇上这个问题,真是费劲,idea调试没问题,打jar包后再linux’服务器上运行就报错ClassNotfund我的解决办法如下:

1.首先检查你的jar包是否已经引入

idea是在file-》project structure-》Libraries中

2.在pom中添加你的jar包路径

你需要修改一下路径指向你的jar包。 ${project.basedir}指向根目录,即src所在目录。 system一定要有!

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

3.在pom中添加编译插件

版本和你的springboot版本保持一致 true一定要有!!

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <version>2.1.6.RELEASE</version>
    <configuration>
        <includeSystemScope>true</includeSystemScope>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>repackage</goal>
            </goals>
        </execution>
    </executions>
</plugin>

打包运行一下,问题应该已经解决了,很开心能够帮助到你~