本文侧重讲解如何将已经按照好的 Maven 和 Nexus 连接,即如何通过 Maven 部署 artifact 到 Nexus。

本文前提:

1. 安装好 Maven。可以使用 Maven 创建、打包项目。关于安装

2. 安装好 Nexus。可以访问本地的 Nexus 仓库 http://localhost:8081/nexus/#welcome 。

正文:

1. 配置 Maven 的配置文件 settings.xml 和 项目的说明文件 pom.xml ,使得 Maven 知道往哪里部署 ,已经有权限部署 。

在 setting.xml 中 :

     <servers>
<server>
<id>xxx-nexus</id>
<username>deployment</username>
<password>{deployment_pwd}</password>
</server>
</servers>

建议使用 deployment 账号,这个账号在安装好 Nexus 后就有了,默认密码是 deployment123 , 可以修改此密码。

在 pom.xml 中 :

  <distributionManagement>
<!-- Publish the versioned releases here -->
<repository>
<id>xxx-nexus</id>
<name>vineetmanohar nexus</name>
<url>http://localhost:8081/nexus/content/repositories/releases/</url>
</repository> <!-- Publish the versioned releases here -->
<snapshotRepository>
<id>xxx-nexus</id>
<name>vineetmanohar nexus</name>
<url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>

注意一,这里 <repository> 元素 和 <snapshotRepository> 元素的 id 应该和 settings.xml 中的 id 保持一致,使得库位置 和 库账号密码能对的上。

注意二, <repository> 元素的 url 和 <snapshotRepository> 元素的 url 应该应该是不一样的。我第一次配置的时候把上面的 url 值直接 copy 到下面的 url ,导致报错 :

Could not transfer artifact com.tony.aaa:webTT:war:1.0-20160124.105254- from/to vineetmanohar-nexus (http://localhost:/nexus/content/repositories/releases/) ...... Return code is: , ReasonPhrase: Bad Request. 

2. 添加部署插件

使用 nexus-staging-maven-plugin 插件,使得部署更顺利。

在 pom.xml 中:

      <plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.5.1</version>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
<configuration>
<serverId>nexus</serverId>
<nexusUrl>http://localhost:8081/nexus/</nexusUrl>
<skipStaging>true</skipStaging>
</configuration>
</plugin>
</plugins>

3. 执行部署命令

mvn clean deploy -Dmaven.test.skip=true

执行完后,应该看到类似的 :

....
Uploading: http://localhost:8081/nexus/content/repositories/snapshots/com/tony/aaa/webTT/maven-metadata.xml
Uploaded: http://localhost:8081/nexus/content/repositories/snapshots/com/tony/aaa/webTT/maven-metadata.xml (275 B at 13.4 KB/sec)
[INFO] * Bulk deploy of locally gathered snapshot artifacts finished.
[INFO] Remote deploy finished with success.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.689 s
[INFO] Finished at: 2016-01-24T21:12:28+08:00
[INFO] Final Memory: 16M/240M
[INFO] ------------------------------------------------------------------------

表示部署成功。然后可以到 Nexus 看到类似如下的结果 :

至此,部署完成。

参考资料 :

Maven Deploy to Nexus, Baelduang ,Maven 部署教程

"Bad Request" Error when deploying an artifact in Nexus

Getting started with Nexus Maven Repo Manager, Vineet Manohar's blog ,很好的教程,其中包含如何配置 Nexus 安全

Repository Management with Nexus 看了前三章,了解了关于 Nexus 的基本概念

Maven Tutorial - TutorialsPoint 很好的教程,看完能大致了解和使用 Maven.

Welcome to Apache Maven, Apache Maven 官网,关于 Maven 的细节可以在里面查找。

最新文章

  1. Java双循环break的用法
  2. 使用递归方法遍历TreeView的节点如配置则勾选
  3. Codeforces Alpha Round #20 (Codeforces format) C. Dijkstra?(裸的dijkstra)
  4. Node.js 全局对象
  5. 实现无锁的栈与队列(5):Hazard Pointer
  6. SQL 总汇
  7. javascript练习----复选框全选,全不选,反选
  8. poj3347Kadj Squares
  9. app启动其他应用
  10. ios数组基本用法和排序
  11. 7-1 vim 编辑器
  12. Android开发8:数据存储(二)——SQLite数据库和ContentProvider的使用
  13. BZOJ_2460_[BeiJing2011]元素_线性基
  14. 域名注册域名解析域名绑定 dns服务器解析 域名记录的添加 记录类型含义@ www 访问域名请求过程
  15. pl/sql调试存储过程
  16. C# 制作向导
  17. IO流(5)—缓冲流
  18. idea 在tomcat启动的时候发现控制台输出的是乱码
  19. svn转git合并代码
  20. 什么是GPS的冷启动、温启动和热启动?

热门文章

  1. 解决Ubuntu 14.04 下SMPlayer的字幕乱码问题
  2. request.getAttribute( &quot;result&quot;);和request.setAttribute(&quot;result&quot;,username);
  3. (转)如何将ecshop首页主广告位的flash轮播替换为js轮播
  4. iOS 格式化输出符号与类型转换
  5. C# 、winform 添加皮肤后(IrisSkin2) label设置的颜色 无法显示
  6. bootstrap弹出框居中
  7. 66 Plus One(大数+1Easy)
  8. table表格cellspacing与cellpadding属性
  9. 切换samba用户
  10. CentOS 基础安装