参考博客:https://www.cnblogs.com/mask-xiexie/p/16086612.html
https://zhuanlan.zhihu.com/p/587605618
1、在resources目录下新建lib文件夹,将jar包放到lib文件夹中
2、修改pom.xml文件
<dependency>
<groupId>com.lanren312</groupId>
<artifactId>lanren312</artifactId>
<scope>system</scope>
<version>1.0</version>
<systemPath>${project.basedir}/src/main/resources/lib/javatest.jar</systemPath>
</dependency>
备注:
groupId、artifactId、version这三个随便写
scope=system表示此依赖是来自外部jar,而不是maven仓库。当scope设置为system时,systemPath属性才会生效,systemPath为一个物理文件路径,来指定依赖的jar其物理磁盘的位置。
${project.basedir}固定写法
现在运行项目没有问题,但是打包就会发现jar包下 \BOOT-INF\lib\ 目录下没有我们刚刚添加的包,看下面的步骤
3、打jar、war包
packaging、build对应改下
<packaging>jar</packaging>
<!-- <packaging>war</packaging>-->
<build>
<finalName>heroes</finalName>
<resources>
<resource>
<directory>lib</directory>
<targetPath>/lib/</targetPath>
<includes>
<include>${project.basedir}/src/main/resources/lib/</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
<!-- 定义war包插件 -->
<!-- <plugin>-->
<!-- <groupId>org.apache.maven.plugins</groupId>-->
<!-- <artifactId>maven-war-plugin</artifactId>-->
<!-- <configuration>-->
<!-- <webResources>-->
<!-- <resource>-->
<!-- <directory>src/main/resources/lib</directory>-->
<!-- <targetPath>WEB-INF/lib/</targetPath>-->
<!-- <includes>-->
<!-- <include>**/*.jar</include>-->
<!-- </includes>-->
<!-- </resource>-->
<!-- </webResources>-->
<!-- </configuration>-->
<!-- </plugin>-->
<!-- 定义jar包插件 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
</plugins>
</build>
打jar包,在 \BOOT-INF\lib\ 就会看到 lanren312-1.0.jar
打war包,在 \WEB-INF\lib\ 就会看到 javatest.jar
4、 添加web.xml
参考博客 :https://blank.blog.csdn.net/article/details/85337396