怎么通过mvn加载自己写的或第三方的jar包到本地mvn仓库

Guide to installing 3rd party JARs Although rarely, but sometimes you will have 3rd party JARs that you need to put in your local repository for use in your builds, since they don...

Guide to installing 3rd party JARs


Although rarely, but sometimes you will have 3rd party JARs that you need to put in your local repository for use in your builds, since they don't exist in any public repository like Maven Central. The JARs must be placed in the local repository in the correct place in order for it to be correctly picked up by Apache Maven. To make this easier, and less error prone, we have provide a goal in the maven-install-plugin which should make this relatively painless. To install a JAR in the local repository use the following command:


mvn install:install-file -Dfile=<path-to-file>-DgroupId=<group-id> \

-DartifactId=<artifact-id>-Dversion=<version>-Dpackaging=<packaging>

If there's a pom-file as well, you can install it with the following command:


mvn install:install-file -Dfile=<path-to-file>-DpomFile=<path-to-pomfile>

With version 2.5 of the maven-install-plugin it gets even better. If the JAR was built by Apache Maven, it'll contain a pom.xml in a subfolder of the META-INF directory, which will be read by default. In that case, all you need to do is:

mvn install:install-file -Dfile=<path-to-file>


示例:

mvn install:install-file -Dfile=/root/hiiposm_engine_simple-2.0.0.26.jar -DgroupId=hiiposm_engine_simple -DartifactId=hiiposm_engine_simple -Dversion=2.0.0.26 -Dpackaging=jar

如果不在jar包位于的目录执行命令,Dfile 后面跟绝对路径,并且jar 包不能位于 位于mvn默认安装的目录内,否则提示存在。

如果提示pom.xml 文件不存在,则需要加上双引号


mvn install:install-file "-Dfile=.\gexin-rp-sdk-http-4.1.1.4.jar" "-DgroupId=com.gexin.platform"  "-DartifactId=gexin-rp-sdk-http" "-Dversion=4.1.2.0" "-Dpackaging=jar"


下面是如何把依赖包放到私有仓库上:

 mvn deploy:deploy-file   -DgroupId=com.aspose   -DartifactId=aspose-words  -Dversion=16.8.0   -Dpackaging=jar   -Dfile=./aspose-words-16.8.0.jar   -DrepositoryId=nexus-release   -Durl=https://repo.myprivate.com/repository/mth-maven-hosted-release


其中 DrepositoryId=nexus-release   为maven settings.conf文件中设置的认证信息

参考链接:http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

  • 发表于 2018-07-19 15:17
  • 阅读 ( 79 )

你可能感兴趣的文章

相关问题

0 条评论

请先 登录 后评论
shitian
shitian

662 篇文章

作家榜 »

  1. shitian 662 文章
  2. 石天 437 文章
  3. 每天惠23 33 文章
  4. 小A 29 文章