有时我们要用的 maven 依赖项在官方repo库中找不到,然而我们从其他渠道获得了依赖项中的所有jar文件,本文记录了如何向本地库添加jar文件。
从复杂到简单,有三种方法:
- 使用 maven 的仓库管理器(例如Nexus)来架设一个本地仓库服务器
- 使用指令 mvn install:install-file 将jar文件安装到本地仓库
- 通过项目pom配置文件引入
第一种方法有利于团队开发,内容多一点,我打算单独用一篇文章记录。这里介绍其他两种方法:
使用指令 mvn install:install-file 将jar文件安装到本地仓库
语法规范:
mvn install:install-file
-Dfile=<path-to-file>
-DgroupId=<group-id>
-DartifactId=<artifact-id>
-Dversion=<version>
-Dpackaging=<packaging>
-DgeneratePom=true
Where: <path-to-file> the path to the file to load
<group-id> the group that the file should be registered under
<artifact-id> the artifact name for the file
<version> the version of the file
<packaging> the packaging of the file e.g. jar
我们以文件<not-yet-commons-ssl-0.3.17.jar>为例:
mvn install:install-file
-Dfile=e:\not-yet-commons-ssl-0.3.17.jar
-DgroupId=org.apache.commons
-DartifactId=not-yet-commons-ssl
-Dversion=0.3.17
-Dpackaging=jar
-DgeneratePom=true