打包不报错,部署到服务器上就报错。把打好的jar包复制出来,解压jar包,查看文件夹
BOOT-INF/lib/ 就能看到你的第三方jar包是否成功导入,包名一定要看清楚,因为你pom中引用的包名和已经打包好的包名是不一致的, 就好比如我在pom中引入的包名为taobao-sdk-java-auto.jar,但是在打包好的jar中就变成了taobaosdk.jar
项目在SpringBoot中运行成功,部署到服务器后(我以jar包运行),提示 Caused by: java.lang.ClassNotFoundException: ....
原帖解决地址:https://github.com/zhanyeye/dingtalk-springboot/issues/2
maven项目通过在pom添加依赖导入本地jar包。项目部署打成 jar包后,运行时会出现java.lang.NoClassDefFoundError
, 并且解压jar包发现BOOT-INF/lib下没有之前引入jar包
<!--添加外部依赖--> <dependency> <groupId>com.dingtalk.open</groupId> <artifactId>taobao-sdk-java-auto</artifactId> <version>2019.12.05</version> <scope>system</scope> <systemPath>${basedir}/src/main/resources/lib/taobao-sdk-java-auto.jar</systemPath> </dependency>
解决方案
我们需要在pom中给springboot的打包插件设置includeSystemScope参数
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <includeSystemScope>true</includeSystemScope> </configuration> </plugin> </plugins> </build>
重点在于
<configuration> <includeSystemScope>true</includeSystemScope> </configuration>
我也pom中加入了
<resources> <resource> <directory>src/lib</directory> <targetPath>BOOT-INF/lib/</targetPath> <includes> <include>**/*.jar</include> </includes> </resource> <resource> <directory>src/main/resources</directory> <targetPath>BOOT-INF/classes/</targetPath> </resource> </resources>