项目已springboot为主,有时候我们需要引入的jar包并非maven公共库中存在(这里不谈私自搭建私库),那我们能否像普通的工程一样,导入自己手动添加的jar包文件呢?
答案是肯定的,来,一起往下看,首先在resource/ 下自建 lib 目录

然后,我们在pom.xml里添加如下配置
1<!-- 引入本地jar --> 2 <dependency> 3 <groupId>xxxxxx</groupId> 4 <artifactId>xxxxx</artifactId> 5 <version>xxxxxx</version> 6 <scope>system</scope> 7 <systemPath>${project.basedir}/src/main/resources/lib/aspose-words-18.9-jdk16.jar</systemPath> 8 </dependency>
这里的 ${project.basedir} 就是本工程的当前根路径, 至于 groupId artifactId version ,可以根据jar包的文件名,自行定义。
到这里,我们已经可以正常使用了,请使用各自的IDE试试就明白了。
那么,下面的问题,我们打包出去后,会发现,发行包里,并不会存在这个自行加载的JAR包,咋办?继续往下看。
1<build> 2 <plugins> 3 <plugin> 4 <groupId>org.springframework.boot</groupId> 5 <artifactId>spring-boot-maven-plugin</artifactId> 6 <!-- 将外部的jar打包到自身jar文件里 --> 7 <configuration> 8 <includeSystemScope>true</includeSystemScope> 9 </configuration> 10 </plugin> 11 </plugins> 12 </build>
只要按照上面的配置,继续修改pom.xml内容即可。
好了,大功告成。
最后,欢迎转载,但请标注原著地址,谢谢。