zoukankan      html  css  js  c++  java
  • 使用nexus替代artifactory作为maven私服

    关键字: nexus
    1. 首先下载Nexus
        从官网http://nexus.sonatype.org/download.html下载下载最新版本,因为是在windows上安装,因此下载的是zip版本,大小大概是16m。
       
    2. 安装
        简单解压缩下载的zip包到安装目录就可以了。
        可执行文件在%nexus安装目录%"nexus-webapp-1.0.0"binjsw"windows-x86-32下:
            InstallNexus.bat/UninstallNexus.bat是安装/卸载nexus为windows service,如果需要设置nexus为开机自动启动就可以安装为windows service然后设置启动方式为自动。
            Nexus.bat是直接在命令行中启动Nexus,如果不想安装Nexus为windows service,可以用这个文件来手工控制Nexus的启动退出。
           
           
    3. 配置nexus

        首先登录,默认地址http://localhost:8081/nexus/,默认用户名密码为admin/admin123.
       
        最重要的一件事情就是开启远程索引下载,索引这个功能实在是太好用了。
       
        nexus默认是关闭远程索引下载功能的,主要是担心会造成对服务器的巨大负担,需要我们手工开启。
       
        开启的方式:
            点击Administration菜单下面的Repositories,将这三个仓库Apache Snapshots,Codehaus Snapshots,Maven Central的Download Remote Indexes修改为true。然后在这三个仓库上分别右键,选择Re-index,这样Nexus就会去下载远程的索引文件。
           
    4. 配置maven
        要让maven使用nexus作为私服,需要做一些设置,使用和原来设置artifactory相似的方法。修改~/.m2/settings.xml.
       
        增加nexus的profile:

        <profile>
          <id>nexus</id>
          <repositories>
            <repository>
                <id>nexus</id>
                <name>local private nexus</name>
                <url>http://localhost:8081/nexus/content/groups/public</url>
                <releases><enabled>true</enabled></releases>
                <snapshots><enabled>false</enabled></snapshots>
            </repository>
            <repository>
                <id>nexus</id>
                <name>local private nexus</name>
                <url>http://localhost:8081/nexus/content/groups/public-snapshots</url>
                <releases><enabled>false</enabled></releases>
                <snapshots><enabled>true</enabled></snapshots>
            </repository>
          </repositories>
          <pluginRepositories>
            <pluginRepository>
                <id>nexus</id>
                <name>local private nexus</name>
                <url>http://localhost:8081/nexus/content/groups/public</url>
                <releases><enabled>true</enabled></releases>
                <snapshots><enabled>false</enabled></snapshots>
            </pluginRepository>
            <pluginRepository>
                <id>nexus</id>
                <name>local private nexus</name>
                <url>http://localhost:8081/nexus/content/groups/public-snapshots</url>
                <releases><enabled>false</enabled></releases>
                <snapshots><enabled>true</enabled></snapshots>
            </pluginRepository>
           </pluginRepositories>
        </profile> 
        修改activeProfiles为:
          <activeProfiles>
            <activeProfile>nexus</activeProfile>
          </activeProfiles>     
    5. 为nexus增加Artifact
        有些特殊的Artifact无法从maven官网仓库中下载,比如sun的一些包,只好自己自行下载后添加到私服中。
        在nexus中我选择将这些Artifact上传到默认安装就存在的仓库3rd Party中,右击仓库名,选择Upload Artifact。
       
    6. 在eclipse中使用索引功能
        原来试过,使用artifactory私服也可以使用Artifact的索引功能,但是由于不知道怎么设置远程仓库的index,我只会设置
        当前artifactory私服已有的Artifact的索引,对于还没有导入到artifactory私服的Artifact就没有办法索引了,很不方便,
        毕竟刚开始使用maven时,所有用到的Artifact都是本地和私服没有而需要到远程仓库取的。
       
        nexus中可以很方便的得到远程仓库的Artifact的索引,在上面“3. 配置nexus”就介绍过。下面介绍如何在eclispe里面
        设置和使用索引功能:
        1) 打开Maven Indexes 的eclispe view
            在eclispe中选择window -> show view -> other ... -> Maven -> Maven Indexes
        2) 添加nexus的index
            右键菜单中选"add index", 在弹出的"Add Respository index"窗口中填入:
                Repository URL: http://localhost:8081/nexus/content/groups/public
                Repository Id: nexus
                Index Update URL: 放空,暂时还不知道该怎么填
            加入后eclispe会自动load一次index信息,然后就可以在新加入的index下可以拉出极大数量的Artifact信息。
        3) 测试一下使用
            找个pom.xml文件,右键 -> Add Dependency, 然后填入一个关键词,比如我填入mina,马上填出和mina相关的一些
            选择,我找到apache mina,双击最新一个版本。会自动在pom.xml文件中增加以下内容:

            <dependency>
                <groupId>org.apache.directory.mina</groupId>
                <artifactId>mina-core</artifactId>
                <version>0.9.5</version>
            </dependency>
            然后Maven自动下载jar包,再将jar包加入项目的build path,全程自动化处理,真是爽啊。

    7. 为nexus增加新的proxy  repository
            方法很简单,administration -> Repositories -> add -> proxy,填写后保存即可。但是要注意,nexus不会自动将新加入的repository添加到group中,而我们一般喜欢直接使用默认的"public repository" group, 比如前面我在maven的profile中就只设置了这一个URL: http://localhost:8081/nexus/content/groups/public。因此需要手工修改"public repository" group的设置,将刚才添加的proxy  repository加到组中。
            推荐的repository有:
                    1) jboss         http://repository.jboss.com/maven2/
                    2) sun            http://download.java.net/maven/2/
                    3)k-int           http://developer.k-int.com/maven2/
                            加入这个纯粹是因为它有sun的jmxri/jmxtools这些Artifact,强烈鄙视sun,自己的官方repository居然没有。
    8. 总结
        很明显,nexus无论是在界面,功能,操作上,都比artifactory强大的多。
        因此推荐大家使用nexus替代artifactory作为maven私服。
  • 相关阅读:
    Ext JS学习第三天 我们所熟悉的javascript(二)
    Ext JS学习第二天 我们所熟悉的javascript(一)
    Ext JS学习第十七天 事件机制event(二)
    Ext JS学习第十六天 事件机制event(一)
    Ext JS学习第十五天 Ext基础之 Ext.DomQuery
    Ext JS学习第十四天 Ext基础之 Ext.DomHelper
    Ext JS学习第十三天 Ext基础之 Ext.Element
    Ext JS学习第十天 Ext基础之 扩展原生的javascript对象(二)
    针对错误 “服务器提交了协议冲突. Section=ResponseHeader Detail=CR 后面必须是 LF” 的原因分析
    C# 使用HttpWebRequest通过PHP接口 上传文件
  • 原文地址:https://www.cnblogs.com/baoguo/p/1403145.html
Copyright © 2011-2022 走看看