`
blueram
  • 浏览: 757305 次
  • 性别: Icon_minigender_1
  • 来自: 郑州
社区版块
存档分类
最新评论

maven nexus的使用

 
阅读更多

搭建maven私服,解决速度问题。

我使用了一个破解的版本,遇到的小问题。

1、索引问题

开始以为不可用,就update index,等了好久发现下载了,但是还是不可以使用。

配置{M2_HOME}/setting.xml,或者修改~/.m2/settings.xml.后者优先级大于前者,pom.xml的优先级最高了。

  <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居然没有。
                4)sonatype        http://repository.sonatype.org/content/groups/public/
8. 总结
    很明显,nexus无论是在界面,功能,操作上,都比artifactory强大的多。
    因此推荐大家使用nexus替代artifactory作为maven私服。
    
updates:
1.  2008.11.28  
由于公司升级操作系统,告别老旧不堪的windows2000升级到vista,因此重新安装了nexus. 新版本的nexus似乎增加了不少小的功能比如对remote index的支持,具体没有深究,不过能不断更新实在是很令人欣慰。以后就打算用nexus了。

2. 2009.10.15
    一年来陆续发现了一些比较不错的maven仓库
    1) fedora.is     
        http://fedora.is/maven/
    2) ibiblio
        http://mirrors.ibiblio.org/pub/mirrors/maven2/
        这个是ivy的官网,东西比较多
    3) rothamsted
        http://ondex.rothamsted.bbsrc.ac.uk/nexus/content/repositories/releases/
        http://ondex.rothamsted.bbsrc.ac.uk/nexus/content/repositories/wso2/
        有一些比较偏门的东西

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics