前言
使用外部手動添加的jar到項目,打包時出現jar找不到問題解決
處理
例如項目結構如下
引入方式換成這種
<!-- 除了一下這兩種引入外部jar,還是可以將外部jar包添加到maven中(百度查)--><!-- pdf轉word --><dependency><groupId>com.aspose</groupId><artifactId>aspose-pdf</artifactId><version>22.5</version><scope>system</scope><systemPath>${project.basedir}/lib/aspose-pdf-22.5.cracked.jar</systemPath></dependency><!-- excel轉pdf --><dependency><groupId>com.external</groupId><artifactId>aspose-cells</artifactId><version>8.5.2</version><scope>system</scope><systemPath>${project.basedir}/lib/aspose-cells-8.5.2.jar</systemPath></dependency>
這里打包war生成的jar會在lib-provided,所以要指定,不然就算打包成功也會報錯找不到類的
<build><plugins><!-- 打包外部jar需要--><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><includeSystemScope>true</includeSystemScope></configuration></plugin><!-- 打包war防止上面引入的本地jar添加到 lib-provided 文件夾中而讀取不了--><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-war-plugin</artifactId><configuration><webResources><resource><directory>${project.basedir}/lib</directory><targetPath>WEB-INF/lib/</targetPath><includes><include>**/*.jar</include></includes></resource></webResources></configuration></plugin></plugins></build>
這樣打包后即可!
你也可以將這些jar包添加到本地maven然后正常引入
如,參考博客
1參考:https://blog.csdn.net/qq_33610816/article/details/121230093
2參考:https://cloud.tencent.com/developer/article/2225546?areaSource=102001.5&traceId=qhV21ynId-ZXtcVdb5DYN