nexus下载地址:

http://www.sonatype.org/nexus/archived/#step2top

1、 为什么使用Nexus

如果没有私服,我们所需的所有构件都需要通过maven的中央仓库和第三方的Maven仓库下载到本地,而一个团队中的所有人都重复的从maven仓库下载构件无疑加大了仓库的负载和浪费了外网带宽,如果网速慢的话,还会影响项目的进程。很多情况下项目的开发都是在内网进行的,连接不到maven仓库怎么办呢?开发的公共构件怎么让其它项目使用?这个时候我们不得不为自己的团队搭建属于自己的maven私服,这样既节省了网络带宽也会加速项目搭建的进程,当然前提条件就是你的私服中拥有项目所需的所有构件。

2、Nexus下载

下载地址:http://www.sonatype.org/nexus/go

3、Nexus启动

我下载的是zip包,解压后进入\nexus-2.1.2-bundle\nexus-2.1.2\bin\jsw\,根据操作系统类型选择文件夹,我选的是windows-x86-32文件夹,进入后可看到如下所示bat文件。

双击console-nexus.bat运行。游览器中输入http://127.0.0.1:8081/nexus/,出现图(2)所示就代表nexus已经启动成功。

8081为默认的端口号,要修改端口号可进入nexus-2.1.2-bundle\nexus-2.1.2\conf\打开nexus.properties文件,修改application-port属性值就可以了。

默认的用户名和密码:admin/admin123,登录后看到图(3)所示:

图(3)

4、Nexus仓库

nexus的仓库类型分为以下四种:

group: 仓库组

hosted:宿主

proxy:代理

virtual:虚拟

首次登陆nexus后可以看到以下一个仓库组和多个仓库。


   Public Repositories:  仓库组

3rd party: 无法从公共仓库获得的第三方发布版本的构件仓库

Apache Snapshots: 用了代理ApacheMaven仓库快照版本的构件仓库

Central: 用来代理maven中央仓库中发布版本构件的仓库

Central M1 shadow: 用于提供中央仓库中M1格式的发布版本的构件镜像仓库

Codehaus Snapshots: 用来代理CodehausMaven 仓库的快照版本构件的仓库

Releases: 用来部署管理内部的发布版本构件的宿主类型仓库

Snapshots:用来部署管理内部的快照版本构件的宿主类型仓库

4.1、创建Nexus宿主仓库

在Repositories选项页的菜单栏上点击Add按钮会出现如下所示,选择要添加的仓库类型。

这里我点击添加宿主类型的仓库,在仓库列表的下方会出现新增仓库的配置,如下所示:

 点击save按钮后就会在仓库列表中看到刚才新增的仓库。
4.2、创建Nexus代理仓库

点击菜单栏上的Add按钮后选择Proxy Repository,看到如下所示配置界面:

4.3、创建Nexus仓库组

仓库组和仓库关系是一对多的关系,一个仓库组可以指向多个仓库。

点击菜单栏上的Add按钮选择Repository Group就可以看到仓库组的配置界面,如下所示:

 

点击save后就可在仓库列表中看到新增的仓库组了,项目中如果要下载构件的话,配置文件中一般都用仓库组的URL。

5、修改Maven配置文件从Nexus下载构件

1)
如果想对操作系统的所有用户统一配置maven,则只需修改maven\conf\setting.xml
文件就可以了,如果只想对用户单独配置maven,只需将conf\setting.xml文件复制到C:\Documents and
Settings\Administrator\.m2文件夹下(我这里假设系统装在c盘,用户为Administrator)。

2)  打开setting.xml文件,可以看到如下代码:

  1. <!-- localRepository
  2. | The path to the local repository maven will use to store artifacts.
  3. |
  4. | Default: ~/.m2/repository
  5. <localRepository></localRepository>
  6. -->
  1. <!-- localRepository
  2. | The path to the local repository maven will use to store artifacts.
  3. |
  4. | Default: ~/.m2/repository
  5. <localRepository></localRepository>
  6. -->

表示如果不设置localRepository,maven会默认将本地仓库建到/.m2/repository文件夹下。

设置localRepository如下代码所示:

  1. <localRepository>F:\myCenterRepository</localRepository>
  1. <localRepository>F:\myCenterRepository</localRepository>

表示在myCenterRepository文件夹下建立本地仓库。个人建议不要采用默认的仓库地址,因为项目如果很多的话,那么本地仓库所占的磁盘空间就比较多了,所以指定仓库地址到其他盘符,更方便管理。

5.2、在POM文件中配置Nexus仓库

在项目的pom文件中添加如下代码:

  1. <repositories>
  2. <repository>
  3. <id>nexus</id>
  4. <name>my-nexus-repository</name>
  5. <url>http://127.0.0.1:7788/nexus/content/groups/public/</url>
  6. <releases>
  7. <enabled>true</enabled>
  8. </releases>
  9. <snapshots>
  10. <enabled>false</enabled>
  11. </snapshots>
  12. </repository>
  13. </repositories>
  14. <pluginRepositories>
  15. <pluginRepository>
  16. <id>nexus</id>
  17. <name>my-nexus-repository</name>
  18. <url>http://127.0.0.1:7788/nexus/content/groups/public/</url>
  19. <releases>
  20. <enabled>true</enabled>
  21. </releases>
  22. <snapshots>
  23. <enabled>false</enabled>
  24. </snapshots>
  25. </pluginRepository>
  26. </pluginRepositories>
  1. <repositories>
  2. <repository>
  3. <id>nexus</id>
  4. <name>my-nexus-repository</name>
  5. <url>http://127.0.0.1:7788/nexus/content/groups/public/</url>
  6. <releases>
  7. <enabled>true</enabled>
  8. </releases>
  9. <snapshots>
  10. <enabled>false</enabled>
  11. </snapshots>
  12. </repository>
  13. </repositories>
  14. <pluginRepositories>
  15. <pluginRepository>
  16. <id>nexus</id>
  17. <name>my-nexus-repository</name>
  18. <url>http://127.0.0.1:7788/nexus/content/groups/public/</url>
  19. <releases>
  20. <enabled>true</enabled>
  21. </releases>
  22. <snapshots>
  23. <enabled>false</enabled>
  24. </snapshots>
  25. </pluginRepository>
  26. </pluginRepositories>

在pom文件中配置只对当前项目有效,而实际开发中不可能在每个项目中重复配置信息,所以不建议在pom文件中配置。

5.3、在setting.xml文件中配置Nexus仓库

1)maven提供了profile来配置仓库信息,如下所示:

  1. <profiles>
  2. <profile>
  3. <id>myprofile</id>
  4. <repositories>
  5. <repository>
  6. <id>central</id>
  7. <url>http://central</url>
  8. <releases>
  9. <enabled>true</enabled>
  10. </releases>
  11. <snapshots>
  12. <enabled>true</enabled>
  13. </snapshots>
  14. </repository>
  15. </repositories>
  16. <pluginRepositories>
  17. <pluginRepository>
  18. <id>central</id>
  19. <url>http://central</url>
  20. <releases>
  21. <enabled>true</enabled>
  22. </releases>
  23. <snapshots>
  24. <enabled>false</enabled>
  25. </snapshots>
  26. </pluginRepository>
  27. </pluginRepositories>
  28. </profile>
  29. </profiles>
  1. <profiles>
  2. <profile>
  3. <id>myprofile</id>
  4. <repositories>
  5. <repository>
  6. <id>central</id>
  7. <url>http://central</url>
  8. <releases>
  9. <enabled>true</enabled>
  10. </releases>
  11. <snapshots>
  12. <enabled>true</enabled>
  13. </snapshots>
  14. </repository>
  15. </repositories>
  16. <pluginRepositories>
  17. <pluginRepository>
  18. <id>central</id>
  19. <url>http://central</url>
  20. <releases>
  21. <enabled>true</enabled>
  22. </releases>
  23. <snapshots>
  24. <enabled>false</enabled>
  25. </snapshots>
  26. </pluginRepository>
  27. </pluginRepositories>
  28. </profile>
  29. </profiles>

2) 激活profile

  1. <activeProfiles>
  2. <activeProfile>myprofile</activeProfile>
  3. </activeProfiles>
  1. <activeProfiles>
  2. <activeProfile>myprofile</activeProfile>
  3. </activeProfiles>
 
3)配置镜像
  1. <mirrors>
  2. <mirror>
  3. <id>nexus</id>
  4. <url>http://127.0.0.1:7788/nexus/content/groups/public/</url>
  5. <mirrorOf>*</mirrorOf>
  6. </mirror>
  7. </mirrors>
  1. <mirrors>
  2. <mirror>
  3. <id>nexus</id>
  4. <url>http://127.0.0.1:7788/nexus/content/groups/public/</url>
  5. <mirrorOf>*</mirrorOf>
  6. </mirror>
  7. </mirrors>

这里配置mirrorOf的值为*,代表maven的所有访问请求都会指向到Nexus仓库组。

6、部署构件到Nexus仓库

6.1、maven部署

1) 修改pom文件

在pom文件中添加如下配置:

  1. <distributionManagement>
  2. <repository>
  3. <id>my-nexus-releases</id>
  4. <url>http://127.0.0.1:7788/nexus/content/repositories/releases/</url>
  5. </repository>
  6. <snapshotRepository>
  7. <id>my-nexus-snapshot</id>
  8. <url>http://127.0.0.1:7788/nexus/content/repositories/snapshots/</url>
  9. </snapshotRepository>
  10. </distributionManagement>
  1. <distributionManagement>
  2. <repository>
  3. <id>my-nexus-releases</id>
  4. <url>http://127.0.0.1:7788/nexus/content/repositories/releases/</url>
  5. </repository>
  6. <snapshotRepository>
  7. <id>my-nexus-snapshot</id>
  8. <url>http://127.0.0.1:7788/nexus/content/repositories/snapshots/</url>
  9. </snapshotRepository>
  10. </distributionManagement>
 2)在setting.xml文件中添加认证信息:
  1. <servers>
  2. <server>
  3. <id>my-nexus-releases</id>
  4. <username>admin</username>
  5. <password>admin123</password>
  6. </server>
  7. <server>
  8. <id>my-nexus-snapshot</id>
  9. <username>admin</username>
  10. <password>admin123</password>
  11. </server>
  12. </servers>
  1. <servers>
  2. <server>
  3. <id>my-nexus-releases</id>
  4. <username>admin</username>
  5. <password>admin123</password>
  6. </server>
  7. <server>
  8. <id>my-nexus-snapshot</id>
  9. <username>admin</username>
  10. <password>admin123</password>
  11. </server>
  12. </servers>
 上面的配置中我用的是超级管理员的账户,开发项目中可以改为具有部署构件权限的用户就可以了。

3)执行部署

测试的构件项目信息如下:

  1. <groupId>com.ez</groupId>
  2. <artifactId>TestJar</artifactId>
  3. <version>1.0</version>
  4. <packaging>jar</packaging>
  5. <name>TestJar</name>
  1. <groupId>com.ez</groupId>
  2. <artifactId>TestJar</artifactId>
  3. <version>1.0</version>
  4. <packaging>jar</packaging>
  5. <name>TestJar</name>

从上面的信息中可以看出构件为发布版本,所以部署构件的话会自动部署至releases仓库中。

在命令行中执行:mvn clean deploy

如果之前没用执行过该命令,maven会自动到中央仓库中下载部署所需的插件。最后在命令行中看到如下所示就代表构件已经部署成功。

到nexus的releases仓库中查看刚刚部署好的构件信息如下所示:

如果部署失败的要检查一下用户是否有部署的权限,目标仓库是否允许部署,是否缺少部署所需的构件。

6.2、手动部署

手动部署构件则更为简单了,在nexus的仓库列表中点击要部署的目标仓库,然后点击Artifact Upload选项卡看到下图所示:

通过以上配置运用Nexus搭建的私服基本上可以用了,更多配置需求可参考Nexus book.

Nexus book下载地址:http://download.csdn.net/detail/yaoqinzhou1943/4589583

Windows 下Nexus搭建Maven私服的更多相关文章

  1. 【原】Windows下Nexus搭建Maven私服

    一.Maven安装 详见Java开发环境搭建 二.Nexus安装 2.1.下载 地址:http://www.sonatype.org/nexus/go/ 选择OSS(ZIP)版本 2.2.安装 将安装 ...

  2. Windows使用Nexus搭建Maven私服

    简介 Maven私服是架设在局域网的一种特殊的远程仓库,目的是代理远程仓库及部署第三方构件,有了私服之后,当 Maven 需要下载构件时,直接请求私服,私服上存在则下载到本地仓库,否则,私服请求外部的 ...

  3. Windows下nexus-3.*搭建Maven私服

    1.下载 从官网下载https://help.sonatype.com/display/NXRM3/Download 选择Windows archive https://download.sonaty ...

  4. ubuntu下使用Nexus搭建Maven私服

    ubuntu下使用Nexus搭建Maven私服 1.私服简介: 私服是架设在局域网的一种特殊的远程仓库,目的是代理远程仓库及部署第三方构件.有了私服之后,当 Maven 需要下载构件时,直接请求私服, ...

  5. Maven——使用Nexus搭建Maven私服

    原文:http://www.cnblogs.com/xdp-gacl/p/4068967.html Maven学习总结(九)--使用Nexus搭建Maven私服 一.搭建nexus私服的目的 为什么要 ...

  6. (转)Maven学习总结(九)——使用Nexus搭建Maven私服

    孤傲苍狼只为成功找方法,不为失败找借口! Maven学习总结(九)——使用Nexus搭建Maven私服 一.搭建nexus私服的目的 为什么要搭建nexus私服,原因很简单,有些公司都不提供外网给项目 ...

  7. 使用Nexus搭建Maven私服问题总结

    #业务场景 最近项目要交付给客户了,之前项目开发和测试一直都是使用公司内部的一套环境,项目交付后客户购置了大量服务器,也要将整套测试环境迁移至客户的服务器上,后续的需求变更以及新需求的开发都会在客户服 ...

  8. Maven 使用Nexus搭建Maven私服

    Maven学习 (四) 使用Nexus搭建Maven私服 为什么要搭建nexus私服,原因很简单,有些公司都不提供外网给项目组人员,因此就不能使用maven访问远程的仓库地址,所以很有必要在局域网里找 ...

  9. 如何使用Nexus搭建Maven私服

    如何使用Nexus搭建Maven私服 听语音 | 浏览:47 | 更新:2016-09-29 10:22 1 2 3 4 5 6 7 分步阅读 一键约师傅 百度师傅最快的到家服务,最优质的电脑清灰! ...

随机推荐

  1. 计蒜客 ACM竞赛高校联盟训练赛 第8场 煎牛排

    水一水. https://nanti.jisuanke.com/t/24205 煎牛排 题目描述 又是一个难得的周六,是时候远离食堂和外卖出去大吃一顿了.圈内知名吃货AA正想着中午去吃汉堡炸鸡烤肉火锅 ...

  2. IOS7开发~错误收集

    1. fatal error: file '/Applications/Xcode5-DP.app/Contents/Developer/Platforms/iPhoneSimulator.platf ...

  3. 从C的声明符到Objective-C的Blocks语法

    原文链接:http://nilsou.com/blog/2013/08/21/objective-c-blocks-syntax/ 在这个post中,我先以C简单和内置复杂的声明开始,直到我们开始接触 ...

  4. [ios]objective-c 协议和委托 (重点基础知识)

    objective-c protocol delegateprotocol-协议,就是使用了这个协议后就要按照这个协议来办事,协议要求实现的方法就一定要实现. delegate-委托,顾名思义就是委托 ...

  5. Android开发常见的Activity中内存泄漏及解决办法

    上一篇文章楼主提到由Context引发的内存泄漏,在这一篇文章里,我们来谈谈Android开发中常见的Activity内存泄漏及解决办法.本文将会以“为什么”“怎么解决”的方式来介绍这几种内存泄漏. ...

  6. VS2010 MFC中 给菜单项添加消息响应函数

    久了没用,居然忘记了该怎样给菜单项添加响应函数了~~~~~~~~T_T 特记于此: 1. 在资源视图的Menu里找到自己要添加的菜单,然后输入菜单项. 2. 右击菜单项选属性,设置Popup为Fals ...

  7. windows 屏幕坐标 窗口坐标 客户区坐标 逻辑坐标 设备坐标之间的关系及转换

    设置坐标映射    (1)Windows坐标系统 Windows坐标系分为逻辑坐标系和设备坐标系两种,GDI支持这两种坐标系.一般而言, GDI的文本和图形输出函数使用逻辑坐标,而在客户区移动或按下鼠 ...

  8. bat文件转换为exe文件

    批处理文件转换为exe文件(简单的处理文件),点击下载 使用超简单的了,不多说.

  9. centos6.5下载

    1.64位系统 http://mirrors.163.com/centos/6.5/isos/x86_64/CentOS-6.5-x86_64-bin-DVD1.iso http://mirrors. ...

  10. ushare编译之 ‘struct sockaddr_storage’ has no member named ‘s_addr’

    编译ushare的时候出现'struct sockaddr_storage' has no member named 's_addr' 这是使用libupnp1.6.19出现版本号不兼容的错误. 解决 ...