Terry.Li-彬

          虛其心,可解天下之問;專其心,可治天下之學;靜其心,可悟天下之理;恒其心,可成天下之業。

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            143 隨筆 :: 344 文章 :: 130 評論 :: 0 Trackbacks
          之前看到過一些Nexus的介紹,由于剛開始接觸maven時使用的私服是artifactory,因此沒有太在意。今天想著既然Nexus能有膽量出來混,應該有點真本事才是,看了一下nexus的安裝介紹,挺簡單的,試試無妨。因此裝上小試了一下,結果喜出望外,nexus的表現非常不錯,尤其是在開啟遠程索引之后,簡直太方便了。

              于是決定放棄artifactory改而使用nexus作為自己的maven私服。恩,慚愧,頗有點喜新厭舊的味道,artifactory才裝上來沒有幾天,就慘遭拋棄......

              整理了一下,全過程記錄如下:

          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私服。
             
          updates:
          1.  2008.11.28 
          由于公司升級操作系統,告別老舊不堪的windows2000升級到vista,因此重新安裝了nexus. 新版本的nexus似乎增加了不少小的功能比如對remote index的支持,具體沒有深究,不過能不斷更新實在是很令人欣慰。以后就打算用nexus了。
             
          posted on 2009-01-05 23:26 禮物 閱讀(1914) 評論(1)  編輯  收藏 所屬分類: Maven2

          評論

          # re: 初學maven(3)-使用nexus替代artifactory作為maven私服 [未登錄] 2009-03-09 09:49 hehe
          然后在這三個倉庫上分別右鍵,選擇Re-index,自動下載設置為TRUE后,不會下載遠程的索引文件,請問什么問題呢?  回復  更多評論
            

          主站蜘蛛池模板: 昂仁县| 开平市| 峨边| 福鼎市| 光泽县| 平谷区| 新和县| 澄江县| 平陆县| 三原县| 辽宁省| 德钦县| 游戏| 永吉县| 沅江市| 金昌市| 三河市| 巴林左旗| 双鸭山市| 洮南市| 苏尼特左旗| 龙泉市| 阿拉善右旗| 海伦市| 兴和县| 稷山县| 铜梁县| 德庆县| 菏泽市| 石楼县| 嘉黎县| 白山市| 纳雍县| 安图县| 商洛市| 曲沃县| 淮阳县| 高阳县| 苍南县| 平远县| 腾冲县|