Maven命令安装jar包到本地仓库

本文介绍了如何使用Maven的install:install-file命令将jar包安装到本地仓库,包括命令示例、参数解释和解决报错方案。关键参数如artifactId、groupId、version和file的说明有助于理解命令的使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

命令:

      mvn install:install-file

示例:

mvn install:install-file -Dfile=unoil-1.0.jar -DgroupId=com.mycompany -DartifactId=unoil -Dversion=1.0 -Dpackaging=jar

有些小伙伴操作时可能会遇到报错情况The goal you specified requires a project to execute but there is no POM in this directory....,这可能与平台相关,博主在windows也遇到过这种情况,解决方案是给参数加上英文输入法下的双引号

mvn install:install-file "-Dfile=unoil-1.0.jar" "-DgroupId=com.mycompany" "-DartifactId=unoil" "-Dversion=1.0" "-Dpackaging=jar"

注意,等号右侧不要留空格,不然会报错

参数解释:

<artifactId>

ArtifactId of the artifact to be installed. Retrieved from POM file if one is specified or extracted from pom.xml in jar if available.

  • Type: java.lang.String
  • Required: No
  • User Property: artifactId

<classifier>

Classifier type of the artifact to be installed. For example, "sources" or "javadoc". Defaults to none which means this is the project's main artifact.

  • Type: java.lang.String
  • Since: 2.2
  • Required: No
  • User Property: classifier

<file>

文件路径

The file to be installed in the local repository.

  • Type: java.io.File
  • Required: Yes
  • User Property: file

<generatePom>

是否生成pom文件,默认为true

Generate a minimal POM for the artifact if none is supplied via the parameter pomFile. Defaults to true if there is no existing POM in the local repository yet.

  • Type: java.lang.Boolean
  • Since: 2.1
  • Required: No
  • User Property: generatePom

<groupId>

GroupId of the artifact to be installed. Retrieved from POM file if one is specified or extracted from pom.xml in jar if available.

  • Type: java.lang.String
  • Required: No
  • User Property: groupId

<javadoc>

The bundled API docs for the artifact.

  • Type: java.io.File
  • Since: 2.3
  • Required: No
  • User Property: javadoc

<localRepositoryPath>

The path for a specific local repository directory. If not specified the local repository path configured in the Maven settings will be used.

  • Type: java.io.File
  • Since: 2.2
  • Required: No
  • User Property: localRepositoryPath

<packaging>

打包方式

Packaging type of the artifact to be installed. Retrieved from POM file if one is specified or extracted from pom.xml in jar if available.

  • Type: java.lang.String
  • Required: No
  • User Property: packaging

<pomFile>

jar包中pom文件的路径

Location of an existing POM file to be installed alongside the main artifact, given by the file parameter.

  • Type: java.io.File
  • Since: 2.1
  • Required: No
  • User Property: pomFile

<sources>

The bundled sources for the artifact.

  • Type: java.io.File
  • Since: 2.3
  • Required: No
  • User Property: sources

<version>

版本号

Version of the artifact to be installed. Retrieved from POM file if one is specified or extracted from pom.xml in jar if available.

  • Type: java.lang.String
  • Required: No
  • User Property: version
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值