Maven deploy上传jar包到远程仓库

1. 前言

Maven 仓库管理也叫 Maven 私服或者代理仓库。使用 Maven 私服有两个目的:

  • 私服是一个介于开发者和远程仓库之间的代理;
  • 私服可以用来部署公司自己的 jar

2. Nexus 介绍

Nexus 是一个强大的 Maven 仓库管理工具,使用 Nexus 可以方便的管理内部仓库同时简化外部仓库的访问。

官网是:www.sonatype.com/

2.1 Nexus安装
  • 下载

下载地址:www.sonatype.com/download-os…

  • 解压

将下载下来的压缩包,拷贝到一个没有中文的路径下,然后解压。

  • 启动

解压之后,打开 cmd 窗口(以管理员身份打开 cmd 窗口),然后定位了 nexus 解压目录,执行 nexus.exe/run 命令启动服务。这个启动稍微有点慢,大概有 1 两分钟的样子。
在这里插入图片描述

启动成功后,浏览器输入 http://lcoalhost:8081 打开管理页面。

打开管理页面后,点击右上角上的登录按钮进行登录,默认的用户名/密码是 admin/admin123。当然,用户也可以点击设置按钮,手动配置其他用户。
在这里插入图片描述

点击 Repositories 可以查看仓库详细信息:
在这里插入图片描述

3. 仓库类型

名称说明
proxy表示这个仓库是一个远程仓库的代理,最典型的就是代理 Maven 中央仓库
hosted宿主仓库,公司自己开发的一些 jar 存放在宿主仓库中,以及一些在 Maven 中央仓库上没有的 jar
group仓库组,包含代理仓库和宿主仓库
virtual虚拟仓库

4. 上传 jar

上传 jar,配置两个地方:

Maven 的 conf/settings.xml 文件配置:

<server>
  <id>releases</id>
  <username>admin</username>
  <password>admin123</password>
</server>
<server>
  <id>snapshots</id>
  <username>admin</username>
  <password>admin123</password>
</server>

在要上传 jar 的项目的 pom.xml 文件中,配置上传路径:

<distributionManagement>
    <repository>
        <id>releases</id>
        <url>http://localhost:8081/repository/maven-releases/</url>
    </repository>
    <snapshotRepository>
        <id>snapshots</id>
        <url>http://localhost:8081/repository/maven-snapshots/</url>
    </snapshotRepository>
</distributionManagement>

配置完成后,点击 deploy 按钮,或者执行 mvn deploy 命令就可以将 jar 上传到私服上。

5. 跳过某个module

I don’t want to deploy one of the artifacts in my multi-module build. Can I skip deployment?
Yes, you can skip deployment of individual modules by configuring the Deploy Plugin as follows:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-deploy-plugin</artifactId>
    <version>2.8.2</version>
    <configuration>
        <skip>true</skip>
    </configuration>
</plugin>

参考:http://maven.apache.org/plugins/maven-deploy-plugin/faq.html

6. 下载私服上的 jar

直接在项目中添加依赖,添加完成后,额外增加私服地址即可:

<repositories>
    <repository>
        <id>local-repository</id>
        <url>http://localhost:8081/repository/maven-public/</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值