一、安装到本地仓库命令:
mvn install:install-file -Dfile=D:\mvn\spring-context-support-3.1.0.RELEASE.jar -DgroupId=org.springframework -DartifactId=spring-context-support -Dversion=3.1.0.RELEASE -Dpackaging=jar
安装到本地仓库的jar,可以在 pom 中正常引入。
二、在 pom 中引入本地jar:
<dependency>
<groupId>xxx.xxx</groupId>
<artifactId>xxxxx</artifactId>
<version>xxx</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/xxx.jar</systemPath>
</dependency>
在 pom 中以 system scope 这种方式引入的 jar,只在 compile 和 test 中有效,不会进行依赖传递,也不包含在打包中。要支持打包需要另外的插件。
以上两种方式都不能实现依赖传递,即不能自动下载引入的 jar 的依赖。即使使用 mvn install 安装 jar 文件到本地仓库,自动生成的 pom 文件中不会有依赖,详细请到本地仓库安装目录中查看对应的 pom 文件即一目了然。
要实现依赖传递,要么在该 jar 的源码项目中使用 mvn install 命令,要么直接修改本地仓库中的该 jar 对应的 pom 文件(注意不是jar包中的 pom,而是同级目录的 pom 文件)。