由于 缺少部分引入jar包,服务器运行jar包时,会出现异常 找不到文件
Constructor threw exception; nested exception is java.lang.NoClassDefFoundError:XXX
引入本地jar包的代码如下:
<dependency>
<groupId>local-sdk</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/local-sdk-1.0.0.jar</systemPath>
</dependency>
其中,${project.basedir} = ${basedir},两者是完全一致的,都是maven的内置属性。
然后会发现,代码不报红了,说明jar包已经引入。
但是,在执行maven编译时,又会报错说找不到这两个包。
解决方案:
一、适用于springboot
重点就 < includeSystemScope > true </ includeSystemScope>这句。
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
</plugins>
</build>
可跳过单元测试
<!--跳过单元测试-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
到此,jar就能成功运行