maven项目部署到Repository(Nexus)

本文将以开源的Nexus为例,演示如何将自己开发的项目部署到Nexus Repository中,解决项目发布、升级的问题。

(一)下载并安装Nexus

    Nexus只需下载war包放到tomcat服务器上便可。



(二)配置Nexus Repository

  1. 打开WEB管理界面:http://localhost:8081/nexus/index.html
  2. 点击右上角Log In进行登录,默认帐号:admin、密码:admin123
  3. 点击左侧Repositories项 -> central仓库 -> Configuration -> Download Remote Indexes=True -> Save,表示下载远程仓库的索引。
  4. 右键central仓库 -> Update Index,更新远程仓库索引到本地,这一步能够加速本地索引。


   说明:

  • 新搭建的neuxs环境只是一个空的仓库,需要手动和远程中心库进行同步,nexus默认是关闭远程索引下载,最重要的一件事情就是开启远程索引下载。 找到右边仓库列表中的三个仓库Apache Snapshots,Codehaus Snapshots和Maven Central,然后再没有仓库的configuration下把Download Remote Indexes修改为true。然后在这三个仓库上分别右键,选择Repari Index,这样Nexus就会去下载远程的索引文件。右键仓库 -> Update Index,更新远程仓库索引到本地,这一步能够加速本地索引
  • 新建公司的内部仓库,步骤为Repositories –> Add –> Hosted Repository,在页面的下半部分输入框中填入Repository ID和Repository Name即可,另外把Deployment Policy设置为Allow Redeploy
  • Nexus中仓库组的概念是Maven没有的,在Maven看来,不管你是hosted也好,proxy也好,或者group也好,对我都是一样的,我只管根据groupId,artifactId,version等信息向你要构件。为了方便Maven的配置,Nexus能够将多个仓库,hosted或者proxy合并成一个group,这样,Maven只需要依赖于一个group,便能使用所有该group包含的仓库的内容。


(三)在项目中配置Nexus Repository的信息

  • 项目pom文件配置distributionManagement

?
1
2
3
4
5
6
7
8
9
10
11
12
    < distributionManagement >
     < repository >
         < id >releases</ id >
         < name >Nexus Release Repository</ name >
         < url >http://localhost:8081/nexus/content/repositories/releases/</ url >
     </ repository >
     < snapshotRepository >
         < id >snapshots</ id >
         < name >Nexus Snapshot Repository</ name >
         < url >http://localhost:8081/nexus/content/repositories/snapshots/</ url >
     </ snapshotRepository >
</ distributionManagement >
  • settings.xml配置账号密码。注意server的id与repository的id必须对应

?
1
2
3
4
5
6
7
8
9
10
11
12
    < servers >
     < server >
         < id >releases</ id >
         < username >admin</ username >
         < password >admin123</ password >
     </ server >
     < server >
         < id >snapshots</ id >
         < username >admin</ username >
         < password >admin123</ password >
     </ server >
</ servers >


(四)发布到Nexus Repository

  • 项目中执行mvn deploy,成功如下所示

[INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ tenpay ---

Uploading: http://localhost:8081/nexus/content/repositories/releases/com/capital/tenpay/1.2/tenpay-1.2.jar
Uploading: http://localhost:8081/nexus/content/repositories/releases/com/capital/tenpay/1.2/tenpay-1.2.pom
Uploaded: http://localhost:8081/nexus/content/repositories/releases/com/capital/tenpay/1.2/tenpay-1.2.pom (2 KB at 9.7 KB/sec)
Uploaded: http://localhost:8081/nexus/content/repositories/releases/com/capital/tenpay/1.2/tenpay-1.2.jar (39 KB at 124.4 KB/sec)
Downloading: http://localhost:8081/nexus/content/repositories/releases/com/capital/tenpay/maven-metadata.xml
Downloaded: http://localhost:8081/nexus/content/repositories/releases/com/capital/tenpay/maven-metadata.xml (347 B at 4.3 KB/sec)
Uploading: http://localhost:8081/nexus/content/repositories/releases/com/capital/tenpay/maven-metadata.xml
Uploaded: http://localhost:8081/nexus/content/repositories/releases/com/capital/tenpay/maven-metadata.xml (376 B at 7.8 KB/sec)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS



http://my.oschina.net/xiaokaceng/blog/169530


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值