上传jar包到Maven仓库

本文介绍如何使用Maven在本地构建并部署Java项目的Jar包到远程仓库,包括配置Maven以解决部署过程中的身份验证问题。

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

进入 /Users/*****/app/common/service/facade  执行 mvn install 即可在target目录下打出jar包
执行以下命令即可将jar包上传到maven仓库
mvn clean install org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy-file \
-Durl=http://mvn.**.net/artifactory/content/repositories/xxx-Releases \
-DrepositoryId=devRepo \
-DgroupId=com.xx.xx \
-DartifactId=xx-common-service-facade \
-Dversion=1.0.0.20180316 \
-Dpackaging=jar \
-Dfile=target/xx-common-service-facade-1.0.0.20180316.jar \
-Dsources=target/xx-common-service-facade-1.0.0.20180316-sources.jar
 
上传jar包的过程中有身份验证,如果身份验证不通过会报以下错误
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy-file (default-cli) on project zappinfo-facade: Failed to deploy artifacts: Could not transfer artifact com.xx.xx:xx-facade:jar:2.0.1.20180314 from/to central (http://mvn.dev.xx.net/artifactory/content/repositories/xx-Releases): Failed to transfer file: http://mvn.dev.xx.net/artifactory/content/repositories/xx-Releases/com/x/zpaas/xx-facade/2.0.1.20180314/xx-facade-2.0.1.20180314.jar. Return code is: 401, ReasonPhrase: Unauthorized. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
 
此时需要在maven的配置文件中添加用户名和密码
 
/Users/xx/program/apache-maven-3.5.2/conf/settings.xml 中配置了maven仓库的用户名密码
  <servers>
     <server>
       <id>devRepo</id>
       <username>xx</username>
       <password>123456</password>
     </server>
</servers>
 
上传jarMaven 仓库需要执行以下步骤: 1. 在本地 Maven 仓库中安装 jar 在命令行中执行以下命令: ``` mvn install:install-file -Dfile=path/to/your.jar -DgroupId=your.group.id -DartifactId=your-artifact-id -Dversion=your-version -Dpackaging=jar ``` 其中,`path/to/your.jar` 是你要上传jar 路径,`your.group.id` 、`your-artifact-id` 和 `your-version` 分别代表你的 Maven 项目的 Group ID、Artifact ID 和版本号。 2. 配置 Maven 项目的 pom.xml 文件 在 Maven 项目的 `pom.xml` 文件中添加以下配置: ``` <repositories> <repository> <id>your-repo-id</id> <url>https://your.repo.url</url> </repository> </repositories> <dependencies> <dependency> <groupId>your.group.id</groupId> <artifactId>your-artifact-id</artifactId> <version>your-version</version> </dependency> </dependencies> <distributionManagement> <repository> <id>your-repo-id</id> <url>https://your.repo.url</url> </repository> </distributionManagement> ``` 其中,`your-repo-id` 和 `https://your.repo.url` 分别代表你的 Maven 仓库的 ID 和 URL。 3. 配置 Maven 的 settings.xml 文件 在 Maven 的 `settings.xml` 文件中添加以下配置: ``` <servers> <server> <id>your-repo-id</id> <username>your-username</username> <password>your-password</password> </server> </servers> ``` 其中,`your-username` 和 `your-password` 分别代表你的 Maven 仓库的用户名和密码。 4. 执行 Mavendeploy 命令 在命令行中执行以下命令: ``` mvn deploy ``` 这将会把你的 jar 上传Maven 仓库中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值