有时候我们需要手动把磁盘里的 jar 包安装到本地的 maven 仓库,以便于maven工程的pom.xml文件引用。如,把 zhdx-license-1.0.jar 安装到本地 maven 仓库的操作如下:
1、确定要引入的依赖项:
<dependency>
<groupId>com.zhdx</groupId>
<artifactId>zhdx-license</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/zhdx-license-1.0.jar</systemPath>
</dependency>
2、在命令行窗口执行 mvn install 指令:
mvn install:install-file -DgroupId=com.zhdx -DartifactId=zhdx-license -Dversion=1.0 -Dpackaging=jar -Dfile=D:\zhdx-license-1.0.jar
为便于阅读,将上述命令分行如下
mvn install:install-file
-DgroupId=com.zhdx
-DartifactId=zhdx-license
-Dversion=1.0
-Dpackaging=jar
-Dfile=D:\zhdx-license-1.0.jar /// jar包在磁盘里的路径
3、maven工程引入该依赖:
<dependency>
<groupId>com.zhdx</groupId>
<artifactId>zhdx-license</artifactId>
<version>1.0</version>
</dependency>