maven引入本地非maven jar包方案

一.最初引入方法

1.ideal引入jar包

ideal -> file-> project Structure? -> Modules -> Dependencies -> JARS or directories? 方式引入項(xiàng)目

2.運(yùn)行項(xiàng)目

開(kāi)心,項(xiàng)目可以正常跑起來(lái)

3.?打包


奇怪的事情發(fā)生了

剛剛引入的包,找不到,報(bào)?java.lang.NoClassDefFoundError

二.解決方法:

1.按上面的方法將引入的jar包刪除

2.在項(xiàng)目下,創(chuàng)建lib目錄,將jar包c(diǎn)opy過(guò)來(lái),重命名為格式:xxx.xxx.xxx-1.3.7.jar? (一定要注意命名方式,會(huì)報(bào)錯(cuò))


3.在項(xiàng)目pom.xml方法增加依賴(lài)包

<dependency>

? ? ? ? ? ? <groupId>com.mytest</groupId>

? ? ? ? ? ? <artifactId>unifiedverification</artifactId>

? ? ? ? ? ? <version>1.3.7</version>

? ? ? ? ? ? <scope>system</scope>

? ? ? ? ? ? <systemPath>${project.basedir}/src/main/lib/com.mytest.unifiedverification-1.3.7.jar</systemPath>

? ? ? ? </dependency>

<systemPath>是引入jar包在項(xiàng)目的路徑

4.重新運(yùn)行,與打包項(xiàng)目? ? 終于正常了,打包完成,在項(xiàng)目target目錄下有打包出來(lái)的jar文件


5.運(yùn)行jar包?java -jar tools-0.0.1-SNAPSHOT.jar

報(bào)了跟上面一樣的錯(cuò)誤,找不到引入jar包的方法

只要是由于maven的 <scope></scope>引起的:scope的配置項(xiàng)可參考https://blog.csdn.net/lz619719265/article/details/82352562

6.解決方法

構(gòu)建增加配置項(xiàng)

? ? ? ? ? ? ? ? <configuration>

? ? ? ? ? ? ? ? ? ? <includeSystemScope>true</includeSystemScope>

? ? ? ? ? ? ? ? </configuration>

pom文件構(gòu)建完整build如下

<build>

? ? ? ? <plugins>

? ? ? ? ? ? <plugin>

? ? ? ? ? ? ? ? <groupId>org.springframework.boot</groupId>

? ? ? ? ? ? ? ? <artifactId>spring-boot-maven-plugin</artifactId>

? ? ? ? ? ? ? ? <configuration>

? ? ? ? ? ? ? ? ? ? <includeSystemScope>true</includeSystemScope>

? ? ? ? ? ? ? ? </configuration>

? ? ? ? ? ? </plugin>

? ? ? ? </plugins>

? ? </build>

7.重新打包,再運(yùn)行jar?包,現(xiàn)在可以正常起服務(wù)了,

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容