开发日常踩坑随笔2023-07-06
在spring-cloud项目中 在src/lib下导入 三方jar包 jenkins编译报错 程序包xxx不存在,原因:因为pom文件中没有添加该jar包依赖 解决办法在pom文件中添加依赖
<dependency>
<groupId>com.xxxx</groupId>
<artifactId>xxxx</artifactId>
<version>1.0.1</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/xxxxx-1.0.1.jar</systemPath>
</dependency>
随后在环境上运行时报错java.lang.NoClassDefFoundError运行时仍然报错没有找到之前jar包定义中的类
报错原因:因为在打包时之前BOOT-INF/lib仍然没有之前的三方jar包,因为POM文件缺少配置<includeSystemScope>true</includeSystemScope>
解决办法 POM文件中加入配置<includeSystemScope>true</includeSystemScope>
<groupId>com.xxxx</groupId>
<artifactId>xxxx</artifactId>
<version>1.0.1</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/xxxxx-1.0.1.jar</systemPath>
</dependency>
随后在环境上运行时报错java.lang.NoClassDefFoundError运行时仍然报错没有找到之前jar包定义中的类
报错原因:因为在打包时之前BOOT-INF/lib仍然没有之前的三方jar包,因为POM文件缺少配置<includeSystemScope>true</includeSystemScope>
解决办法 POM文件中加入配置<includeSystemScope>true</includeSystemScope>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${boot.version}</version>
<configuration>
<fork>true</fork>
<includeSystemScope>true</includeSystemScope>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<encoding>utf-8</encoding>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${boot.version}</version>
<configuration>
<fork>true</fork>
<includeSystemScope>true</includeSystemScope>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<encoding>utf-8</encoding>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>

浙公网安备 33010602011771号