这种情况下有三种做法:
1. 使用intall:install-file命令安装jar包到本地maven仓库,这是最快最直接的解决方法,但是缺点是pom文件将失去可移植性,只能在本地使用。命令如下:
mvn
install
:
install
-
file
-Dfile=path-to-non-maven.jar \
-DgroupId=some-
id
\
-DartifactId=some-artifact \
-Dversion=some-version \
-Dpackaging=jar
|
2. 使用deploye: deploye-file命令把jar包部署到一个可用的在线maven仓库中,比如公司的或者自己在某台机器上架设的(例如Nexus、Artifatory),如果team是在公司的话这个是最好的方式。
3.如果有团队在工作,又没有自己的私有仓库的话,可以建立一个基于文件系统的仓库,但是这种情况下你的依赖不能是system的scoped。这种策略在很多情况下会带来麻烦,所以很多时候弊大于利。
首先在项目中添加一个本地仓库:
<
repositories
>
<
repository
>
<
id
>my-local-repo</
id
>
<
url
>file://${basedir}/my-repo</
url
>
</
repository
>
</
repositories
>
|
然后使用install:install-file命令添加文件到这个本地仓库,因为2.2以前版本的plugin忽略本地地址的参数,所以2.3版本以上使用:
mvn
install
:
install
-
file
-Dfile=<path-to-
file
> -DgroupId=<myGroup> \
-DartifactId=<myArtifactId> -Dversion=<myVersion> \
-Dpackaging=<myPackaging> -DlocalRepositoryPath=<path>
|
来添加,而早期版本使用带有全路径的命令来解决这个问题:
mvn org.apache.maven.plugins:maven-
install
-plugin:2.3.1:
install
-
file
\
-Dfile=<path-to-
file
> -DgroupId=<myGroup> \
-DartifactId=<myArtifactId> -Dversion=<myVersion> \
-Dpackaging=<myPackaging> -DlocalRepositoryPath=<path>
|
最后在项目中添加依赖(不要使用system 的scoped)
<
dependency
>
<
groupId
>your.group.id</
groupId
>
<
artifactId
>3rdparty</
artifactId
>
<
version
>X.Y.Z</
version
>
</
dependency
>