Nexus私服的使用

本文主要介绍,使用maven在nexus私服上传和下载
关于nexus的安装,请参考上篇文章 Windows安装nexus oss3.x

上传jar包到Nexus私服

查看官方文档配置说明 : Configuring Apache Maven
Nexus官方的pdf书籍 : Repository Management With Nexus

修改maven主目录 conf/settings.xml配置文件.添加nexus认证的用户名和密码配置信息

   <server>
          <id>nexus-releases</id>
          <privateKey>admin</privateKey>
          <passphrase>admin123</passphrase>
    </server>
    <server>
          <id>nexus-snapshots</id>
          <privateKey>admin</privateKey>
          <passphrase>admin123</passphrase>
    </server>

在要发布的Project中的 pom.xml 文件中添加如下内容

<distributionManagement>  
    <repository>
      <id>nexus-releases</id>
      <name>Releases</name>
      <url>http://localhost:8081/repository/maven-releases</url>
    </repository>
    <snapshotRepository>
      <id>nexus-snapshots</id>
      <name>Snapshot</name>
      <url>http://localhost:8081/repository/mavensnapshots</url>
    </snapshotRepository>  
</distributionManagement>

注意 : settings.xml 文件中的配置的id名称要和上面的id名称一致

Nexus2可以通过管理界面来上传jar包到私库中,而最新的Nexus3却找不到了上传界面,只能通过以下方式来发布到私库。

Maven配置

在项目中使用 mvn deploy 就可以打包发送到nexus私服上

问题

以上过程中可能会出现的问题 : Return code is 400:
这里写图片描述
因为Nexus中Releases仓库默认的Deployment Policy是Disable Redeploy,部署构件到Releases仓库中可能会出现400的错误
解决办法 : 将Deployment Policy 选项改为 Allow Redeploy,流程如下图:
这里写图片描述

具体其他的问题可以参考下面的链接(讲得非常详细):
http://www.javatang.com/archives/2010/01/23/4518375.html

小结

Snapshot是快照版本,默认每次会把Jar加一个时间戳,做为历史备份版本。
Release上传到私服上的Jar包不会自动带时间戳

下载jar包到本地仓库

下载的jar包可能是本公司的或者中央仓库的,所以使用group仓库来配置

在maven目录下的 conf/settings.xml 下,配置模版

添加镜像

 <mirrors>
    <mirror>
      <!--This sends everything else to /public -->
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <url>http://localhost:8081/repository/maven-public/</url>
    </mirror>
 </mirrors>   
 <profiles>
    <profile>
      <id>nexus</id>
      <!--Enable snapshots for the built in central repo to direct -->
      <!--all requests to nexus via the mirror -->
      <repositories>
        <repository>
          <id>central</id>
          <url>http://localhost:8081/repository/maven-public/</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
      </repositories>
     <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://localhost:8081/repository/maven-public/</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
 </profiles>

激活模版

<activeProfiles>
    <!--make the profile active all the time -->
    <activeProfile>nexus</activeProfile>
</activeProfiles>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值