`

23-参考他人-Nexus安装、使用说明

 
阅读更多

Nexus安装、使用说明  

2013-01-04 17:19:15|  分类: Nexus|举报|字号 订阅

1为什么使用Nexus

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

 

2Nexus下载

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

 

3Nexus启动

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



 

图(1

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



 

 

图(2

 

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

 

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



 

图(3

 

4Nexus仓库

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

               group: 仓库组

               hosted:宿主

              proxy:代理

              virtual:虚拟

 

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



 

图(4

                       Public Repositories:  仓库组

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

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

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

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

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

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

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

 

4.1、创建Nexus宿主仓库

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



 

图(5

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



 

图(6

 

点击save按钮后就会在仓库列表中看到刚才新增的仓库。

 

4.2、创建Nexus代理仓库

 

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



 

 

图(7

 

4.3、创建Nexus仓库组

 

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

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



 

图(8

点击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文件,可以看到如下代码:

[html] view plaincopy

<!--[if !supportLists]-->1.

    <!-- localRepository  
       | The path to the local repository maven will use to store artifacts.  
       |  
      | Default: ~/.m2/repository   
      <localRepository></localRepository>  
     -->  
 

 

 

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

 

设置localRepository如下代码所示:

[html] view plaincopy

 

  <localRepository>F:\myCenterRepository</localRepository>  

 

 

 

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

 

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

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

 

 

 

 

	<repositories>     
	    <repository>     
	      <id>nexus</id>     
	      <name>my-nexus-repository</name>     
	      <url>http://127.0.0.1:7788/nexus/content/groups/public/</url>     
	      <releases>     
	        <enabled>true</enabled>     
	      </releases>     
	      <snapshots>     
	        <enabled>false</enabled>     
	      </snapshots>     
	    </repository>     
	  </repositories>     
	  <pluginRepositories>     
	    <pluginRepository>     
	      <id>nexus</id>     
	      <name>my-nexus-repository</name>     
	      <url>http://127.0.0.1:7788/nexus/content/groups/public/</url>     
	      <releases>     
	        <enabled>true</enabled>     
	      </releases>     
	      <snapshots>     
	        <enabled>false</enabled>     
	      </snapshots>          
	    </pluginRepository>     
	  </pluginRepositories>     

 

 

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

 

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

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

[html] view plaincopy

<!--[if !supportLists]-->1.    

<profiles>  
        <profile>  
          <id>myprofile</id>  
          <repositories>  
                <repository>  
                    <id>central</id>                                     
                    <url>http://central</url>                        
                    <releases>  
                        <enabled>true</enabled>  
                  </releases>  
                  <snapshots>  
                     <enabled>true</enabled>  
                  </snapshots>  
             </repository>  
          </repositories>     
           <pluginRepositories>  
              <pluginRepository>  
                <id>central</id>  
                <url>http://central</url>  
                <releases>  
                 <enabled>true</enabled>  
               </releases>  
                <snapshots>  
                  <enabled>false</enabled>  
                </snapshots>  
             </pluginRepository>  
          </pluginRepositories>  
      </profile>  
  </profiles>  

 

 

 

2) 激活profile

[html] view plaincopy

<!--[if !supportLists]-->1. 

   <activeProfiles>  
        <activeProfile>myprofile</activeProfile>  
     </activeProfiles>  

 

 

 

3)配置镜像

[html] view plaincopy

<!--[if !supportLists]-->1.    

<mirrors>  
      <mirror>     
        <id>nexus</id>      
         <url>http://127.0.0.1:7788/nexus/content/groups/public/</url>     
         <mirrorOf>*</mirrorOf>     
      </mirror>  
    </mirrors> 

  

 

 

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

 

6、部署构件到Nexus仓库

6.1maven部署

1修改pom文件

pom文件中添加如下配置:

[html] view plaincopy

<!--[if !supportLists]-->1.   

 <distributionManagement>  
           <repository>  
              <id>my-nexus-releases</id>  
              <url>http://127.0.0.1:7788/nexus/content/repositories/releases/</url>  
         </repository>  
            
          <snapshotRepository>  
              <id>my-nexus-snapshot</id>  
               <url>http://127.0.0.1:7788/nexus/content/repositories/snapshots/</url>  
         </snapshotRepository>  
    </distributionManagement>  

 

 

2)在setting.xml文件中添加认证信息:

[html] view plaincopy

<!--[if !supportLists]-->1.   

 <servers>  
         <server>  
          <id>my-nexus-releases</id>  
          <username>admin</username>  
          <password>admin123</password>  
        </server>  
        <server>  
         <id>my-nexus-snapshot</id>  
         <username>admin</username>  
        <password>admin123</password>  
     </server>  
  </servers> 

  

 

上面的配置中我用的是超级管理员的账户,开发项目中可以改为具有部署构件权限的用户就可以了。

 

3)执行部署

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

[html] view plaincopy

<!--[if !supportLists]-->1.    

<groupId>com.ez</groupId>  
    <artifactId>TestJar</artifactId>  
      <version>1.0</version>  
     <packaging>jar</packaging>  
     <name>TestJar</name>  

 

 

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

 

在命令行中执行:mvn clean deploy

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



 

图(9

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



 

图(10

 

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

 

6.2、手动部署

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



 

图(11

 

 

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


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

 

 

  • 大小: 54.2 KB
  • 大小: 153.7 KB
  • 大小: 133.6 KB
  • 大小: 81.8 KB
  • 大小: 52.2 KB
  • 大小: 197.3 KB
  • 大小: 205.6 KB
  • 大小: 72.3 KB
  • 大小: 218.1 KB
  • 大小: 78.1 KB
  • 大小: 85.4 KB
  • 大小: 192.8 KB
分享到:
评论

相关推荐

    nexus-3.18.1-01-win64版本的Nexus下载.txt

    本人从官网下载的nexus - 3.18.1-01-win64版本的Nexus.txt

    linux-maven-maven私服nexus安装文档

    linux-maven-maven私服nexus安装文档

    nexus-2.12.0-01-bundle.tar.gz.zip

    网上下载不下来,我通过下载下来的,使用:将下载的压缩包解压到当前目录,然后进入文件夹即可看到 nexus-3.18.0-01-mac.tgz nexus-3.18.0-01-win64.zip nexus-3.18.0-01-unix.tar.gz nexus-2.14.5-02.war nexus-...

    Linux-nexus安装

    Linux-nexus安装Linux-nexus安装Linux-nexus安装Linux-nexus安装Linux-nexus安装Linux-nexus安装Linux-nexus安装

    nexus-3.5.0-02-unix.tar.gz.zip

    使用:将下载的压缩包解压到当前目录,然后进入文件夹即可看到 nexus-3.18.0-01-mac.tgz nexus-3.18.0-01-win64.zip nexus-3.18.0-01-unix.tar.gz nexus-2.14.5-02.war nexus-2.14.13-01-bundle.zip nexus-2.14.13-...

    nexus-2.12.0-01-bundle

    nexus-2.12.0-01-bundle

    nexus-3.5.0-02-win64.zip.zip

    网上下载不下来,我通过下载下来的,使用:将下载的压缩包解压到当前目录,然后进入文件夹即可看到 nexus-3.18.0-01-mac.tgz nexus-3.18.0-01-win64.zip nexus-3.18.0-01-unix.tar.gz nexus-2.14.5-02.war nexus-...

    nexus-3.15.2-01-unix.tar.gz.zip

    网上下载不下来,我通过下载下来的,使用:将下载的压缩包解压到当前目录,然后进入文件夹即可看到 nexus-3.18.0-01-mac.tgz nexus-3.18.0-01-win64.zip nexus-3.18.0-01-unix.tar.gz nexus-2.14.5-02.war nexus-...

    官网下载的professional版:nexus-professional-2.15.1-02-bundle

    Nexus是一套“开箱即用”的系统不需要数据库,它使用文件系统加Lucene来组织数据。 Nexus不是Maven的核心概念,它仅仅是一种衍生出来的特殊的Maven仓库。对于Maven来说,仓库只有两种:本地仓库和远程仓库。 本地...

    nexus-webapp-1.9.2.4安装文件

    nexus-webapp-1.9.2.4安装文件

    apache-maven-3.2.1-nexus

    apache-maven-3.2.1-nexus项目管理工具,64位

    nexus-2.8.1-zip和nexus-2.9.0war小叶

    nexus-2.8.1-zip和nexus-2.9.0war小叶。 nexus-2.8.1-bundle.zip是nexus-2.8.1的安装包,用于maven构建私有仓库服务器 好资源大家一起分享。如果急需用,但是有下载积分的话,关注我,留言我,就OK了。 希望大家关注...

    CCIE-DC Nexus专题视频.zip

    1-Nexus产品介绍 2-Nexus基本系统管理 3-Nexus VDC技术 4-Nexus VDC技术 5-Nexus 基本接口配置实验 5-Nexus基本接口配置 6-Nexus FEX技术 6-Nexus N5K-FEX 7-Nexus Port-Channel介绍 8-Nexus EvPC 8-Nexus N7K-N5K-...

    maven服务器---nexus的使用

    本文档为maven使用手册的后续说明,用于介绍maven服务器---nexus的使用(不会使用m2eclipse插件的,建议先参考m2eclipse插件的使用),与前面的文档一样,都配置了详细的图解,基本做到傻瓜式的照着图片做,就能顺利...

    nexus-3.6.0-02-win64含有安装说明文档.rar

    nexus-3.6.0-02-win64,Windows最新版本,搭建公司内部的maven服务器,含有安装说明文档,亲测可用,安装文档说明很详细

    nexus-2.14.8-01.zip

    Nexus是一个强大的Maven仓库管理器,它极大地简化了自己内部仓库的维护和外部...Nexus 使用ExtJS来开发界面,利用Restlet来提供完整的REST APIs,通过m2eclipse与Eclipse集成使用。Nexus支持WebDAV与LDAP安全身份认证。

    nexus-3.31.1-01-win64.zip

    官网下载 nexus-3.31.1-01-win64 版本;Nexus是一个强大的Maven仓库管理器,...Nexus 使用ExtJS来开发界面,利用Restlet来提供完整的REST APIs,通过m2eclipse与Eclipse集成使用。Nexus支持WebDAV与LDAP安全身份认证。

    nexus-3.18.1-01-unix.zip

    nexus-3.18.1-01-unix.tar.gz wget地址,以方便下载使用

    nexus-3.37.3-02[Windows+Unix]

    Nexus Repository OSS是一款通用的软件包仓库管理(Universal Repository Manager)服务。 压缩包内含: nexus-3.37.3-02-unix.tar.gz nexus-3.37.3-02-win64.zip

    nexus-3.15.2-01-win64

    nexus-3.15.2-01-win64 内网搭建私服

Global site tag (gtag.js) - Google Analytics