前言
使用外部手动添加的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