Maven 安装第三方jar包到本地仓库 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 org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=<path-to-file>

 

https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Maven是一个项目管理工具,它提供了一种简单的方式来管理项目的依赖关系。在使用Maven进行项目开发的过程中,我们经常会遇到引入第三方jar包的需求,从而为项目提供所需的功能。 Maven提供了一种批量安装第三方jar包的功能,可以通过在项目的pom.xml文件中声明依赖关系来实现。首先,我们需要找到所需的第三方jar包Maven坐标,这通常包括groupId、artifactId和version三个属性。 在pom.xml文件中,我们可以通过在dependencies节点下添加多个dependency节点来声明多个第三方jar包的依赖关系。在每个dependency节点内,我们需要填写对应第三方jar包的groupId、artifactId和version属性。 当我们保存并关闭pom.xml文件后,Maven会自动从中央仓库或私有仓库中下载并安装所需的第三方jar包。这样,我们就可以在项目中直接引用这些jar包,并使用其中的类和方法。 除了在pom.xml文件中声明第三方jar包的依赖关系外,我们还可以使用Maven命令进行批量安装。通过执行"mvn install"命令,Maven会按照pom.xml文件中所声明的依赖关系,自动下载并安装所有的第三方jar包。 总之,Maven是一个非常方便的批量安装第三方jar包工具,通过在项目的pom.xml文件中声明依赖关系,我们可以轻松地管理和安装所需的第三方jar包。这样,我们可以快速、高效地开发自己的项目,节省了手动下载和安装第三方jar包的时间和努力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值