本文侧重讲解如何将已经按照好的 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 的细节可以在里面查找。

使用 Maven 部署 artifact 到 Nexus 教程的更多相关文章

  1. maven项目部署到Repository(Nexus)

    目录[-] (一)下载并安装Nexus (二)配置Nexus Repository 说明: (三)在项目中配置Nexus Repository的信息 (四)发布到Nexus Repository 本文 ...

  2. Maven部署异常:on project standalone-pom: Cannot deploy artifact from the local repository解决方法

    MAVEN部署异常 org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache. ...

  3. Gradle Maven部署,转化

    参考:(易百教程)http://www.yiibai.com/gradle/gradle_deployment.html 目录: Gradle部署 Maven转化为Gradle Gradle部署: c ...

  4. maven之如何将自己的写的 maven 构件发布到 nexus 私服

    概念:Nexus服务器是一个代码包管理的服务器,可以理解 Nexus 服务器是一个巨大的 Library 仓库.Nexus 可以支持管理的工具包括 Maven , npm 等,对于 JAVA 开发来说 ...

  5. 阿里云运维部署工具AppDeploy详细教程

    AppDeploy是一个通过SSH实现的命令行工具,可完成应用部署和远程运维管理.当前工具实现为两个版本:普通版(伪代码描述语言)和Python版.Python版使用Python语法规则,可实现您的各 ...

  6. 使用Maven部署构件至私服

    --------------------siwuxie095                                 使用 Maven 部署构件至私服         1.部署构件到 Nexu ...

  7. maven部署tomcat项目,403错误解决

    maven部署tomcat项目时403错误的解决方法 web模块的pom文件 pom.xml <plugin> <groupId>org.apache.tomcat.maven ...

  8. maven部署命令

    参考文档:http://blog.csdn.net/woshixuye/article/details/8133050 http://www.blogjava.net/itvincent/archiv ...

  9. 抗忙,,建个MAVEN的私服仓库-NEXUS

    公司最近需求越来越上轨道,MAVEN的私服仓库-NEXUS构架起来哟.. 参考文档URL: http://www.linuxidc.com/Linux/2011-07/39578p3.htm http ...

随机推荐

  1. 模板-->常系数线性齐次递推(矩阵快速幂)

    如果有相应的OJ题目,欢迎同学们提供相应的链接 相关链接 所有模板的快速链接 Matrix模板 poj_2118_Firepersons,my_ac_code 简单的测试 None 代码模板 /* * ...

  2. codevs2034 01串2

    /* 一开始认为是个水题 直接模拟 没想到只得了50分 一看数据吓niao了 模拟妥妥的TLE 实在不好优化了0.0(最快O(m)) 然后借鉴别人的 DP+神奇的输出 DP:状态:f[i][j] 前i ...

  3. [转]最详细的 HTTPS 科普扫盲帖

    转载自http://www.codeceo.com/article/https-knowledge.html 为什么需要https HTTP是明文传输的,也就意味着,介于发送端.接收端中间的任意节点都 ...

  4. WebStorm shortcuts.

  5. [转]C++基本功和 Design Pattern系列 ctor & dtor

    今天Aear讲的是class.ctor 也就是constructor, 和  class.dtor, destructor. 相信大家都知道constructor 和 destructor是做什么用的 ...

  6. 【USACO 1.2.1】挤牛奶

    [问题描述] 三个农民每天清晨5点起床,然后去牛棚给3头牛挤奶.第一个农民在300时刻(从5点开始计时,秒为单位)给他的牛挤奶,一直到1000时刻.第二个农民在700时刻开始,在 1200时刻结束.第 ...

  7. c语言中3n+1溢出问题解决

    3n+1问题是一个简单有趣而又没有解决的数学问题.这个问题是由L. Collatz在1937年提出的.克拉兹问题(Collatz problem)也被叫做hailstone问题.3n+1问题.Hass ...

  8. ios 中获得应用程序名称和版本号

    IOS程序中的应用名称和版本号在 info.plist 文件中存储着,要想在程序中获得需要使用 NSBundle 对象 下面是示例代码: NSBundle *bundle = [NSBundle ma ...

  9. MVC之序列化

    1.AdminUserInfo.cs [Serializable]序列化类——System.SerializableAttribute 串行化是指存储和获取磁盘文件.内存或其他地方中的对象.在串行化时 ...

  10. FFT快速傅立叶

    Description 给出两个n位10进制整数x和y,你需要计算x*y. Input 第一行一个正整数n.第二行描述一个位数为n的正整数x.第三行描述一个位数为n的正整数y. Output 输出一行 ...