maven引入本地jar包报错:java.lang.NoClassDefFoundError

问题:

maven项目导入自己的jar包,部署到服务器上找不到包, 报错:java.lang.NoClassDefFoundError


解决方案

需要告诉maven,将你感刚刚引入的jar包打进来。

1.引入本地jar:

<dependency>
	 <groupId>com.yinhai</groupId>
	 <artifactId>ta3-compatible-ta3.13-4.0.0-SNAPSHOT.jar</artifactId>
	 <version>3.13-4.0.0</version>
	 <scope>system</scope>
	 <systemPath>${
          
   pom.basedir}/src/main/resources/lib/ta3-compatible-ta3.13-4.0.0-SNAPSHOT.jar</systemPath>
</dependency>

2.告诉maven将本地jar打入:

<plugin>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-maven-plugin</artifactId>
	<configuration>
		<includeSystemScope>true</includeSystemScope>
	</configuration>
</plugin>

maven小常识: maven打包可以控制是否需要将jar打入。通过scope标签

<dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-test</artifactId>
 <scope>test</scope>
</dependency>

scope详解: 没有指定scope,说明scope是compile

参数 解释 是否会被打⼊最终的jar compile 默认的scope 是 test 测试使⽤ 否 provided 编译需要 否 runtime 编译不需要,运⾏时需要(接⼝与实现分离) 是 system 加载本地jar 否
经验分享 程序员 微信小程序 职场和发展