朋友们,好久不见 最近有点忙很久没有活跃了,今天突然发现新来的实习生遇到了一个问题,想了想可能很多刚入行的朋友或许也会受到困扰,在这里简单的发布一些我的解决办法!
在我们写maven项目时偶尔会有一些jar包不存在中央仓库,属于企业内私包或者运维老项目时出现一些包已经不在运维被删除,只能利用本地的jar包进行开发
这里就来讲一下怎么将本地的jar包导入到项目中,并且项目打包部署时能在线上正常使用!
1,首先,将项目的pom路径写好,组织ID,模块ID,版本号,如下所示:我拿自己正在使用的一个包举例:
<dependency>
<groupId>com.ansj</groupId>
<artifactId>response</artifactId>
<version>1.0.0</version>
</dependency>
2,当我们只加上这个直接更新时maven后会报错.中央仓库找不到该版本依赖包,这时候我们就加上以下标签:
<dependency>
<groupId>com.ansj</groupId>
<artifactId>response</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/response-1.0.0.jar</systemPath>
</dependency>
-
<scope>
: 指定依赖项的范围,即在什么情况下该依赖项是可见的。在这里,system
范围表示这是一个系统范围的依赖项。 -
<systemPath>
: 指定系统范围依赖项的路径。 lib包在项目文件下和src同级 -
这样我们就能从本地获取jar包导入到maven
3,这时候我们本地启动就可以正常运行了,但是当我们打包到线上时,启动后会报错找不到类就需要做最后一步,添加 <includeSystemScope>true</includeSystemScope>标签:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
</plugins>
</build>