Terry.Li-彬

          虛其心,可解天下之問;專其心,可治天下之學(xué);靜其心,可悟天下之理;恒其心,可成天下之業(yè)。

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

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

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

          1. 首先下載Nexus
              從官網(wǎng)http://nexus.sonatype.org/download.html下載下載最新版本,因?yàn)槭窃趙indows上安裝,因此下載的是zip版本,大小大概是16m。
             
          2. 安裝
              簡單解壓縮下載的zip包到安裝目錄就可以了。
              可執(zhí)行文件在%nexus安裝目錄%\nexus-webapp-1.0.0\binjsw\windows-x86-32下:
                  InstallNexus.bat/UninstallNexus.bat是安裝/卸載nexus為windows service,如果需要設(shè)置nexus為開機(jī)自動(dòng)啟動(dòng)就可以安裝為windows service然后設(shè)置啟動(dòng)方式為自動(dòng)。
                  Nexus.bat是直接在命令行中啟動(dòng)Nexus,如果不想安裝Nexus為windows service,可以用這個(gè)文件來手工控制Nexus的啟動(dòng)退出。
                 
                 
          3. 配置nexus

              首先登錄,默認(rèn)地址http://localhost:8081/nexus/,默認(rèn)用戶名密碼為admin/admin123.
             
              最重要的一件事情就是開啟遠(yuǎn)程索引下載,索引這個(gè)功能實(shí)在是太好用了。
             
              nexus默認(rèn)是關(guān)閉遠(yuǎn)程索引下載功能的,主要是擔(dān)心會(huì)造成對服務(wù)器的巨大負(fù)擔(dān),需要我們手工開啟。
             
              開啟的方式:
                  點(diǎn)擊Administration菜單下面的Repositories,將這三個(gè)倉庫Apache Snapshots,Codehaus Snapshots,Maven Central的Download Remote Indexes修改為true。然后在這三個(gè)倉庫上分別右鍵,選擇Re-index,這樣Nexus就會(huì)去下載遠(yuǎn)程的索引文件。
                 
          4. 配置maven
              要讓maven使用nexus作為私服,需要做一些設(shè)置,使用和原來設(shè)置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官網(wǎng)倉庫中下載,比如sun的一些包,只好自己自行下載后添加到私服中。
              在nexus中我選擇將這些Artifact上傳到默認(rèn)安裝就存在的倉庫3rd Party中,右擊倉庫名,選擇Upload Artifact。
             
          6. 在eclipse中使用索引功能
              原來試過,使用artifactory私服也可以使用Artifact的索引功能,但是由于不知道怎么設(shè)置遠(yuǎn)程倉庫的index,我只會(huì)設(shè)置
              當(dāng)前artifactory私服已有的Artifact的索引,對于還沒有導(dǎo)入到artifactory私服的Artifact就沒有辦法索引了,很不方便,
              畢竟剛開始使用maven時(shí),所有用到的Artifact都是本地和私服沒有而需要到遠(yuǎn)程倉庫取的。
             
              nexus中可以很方便的得到遠(yuǎn)程倉庫的Artifact的索引,在上面“3. 配置nexus”就介紹過。下面介紹如何在eclispe里面
              設(shè)置和使用索引功能:
              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: 放空,暫時(shí)還不知道該怎么填
                  加入后eclispe會(huì)自動(dòng)load一次index信息,然后就可以在新加入的index下可以拉出極大數(shù)量的Artifact信息。
              3) 測試一下使用
                  找個(gè)pom.xml文件,右鍵 -> Add Dependency, 然后填入一個(gè)關(guān)鍵詞,比如我填入mina,馬上填出和mina相關(guān)的一些
                  選擇,我找到apache mina,雙擊最新一個(gè)版本。會(huì)自動(dòng)在pom.xml文件中增加以下內(nèi)容:

                  <dependency>
                      
          <groupId>org.apache.directory.mina</groupId>
                      
          <artifactId>mina-core</artifactId>
                      
          <version>0.9.5</version>
                  
          </dependency>

                  然后Maven自動(dòng)下載jar包,再將jar包加入項(xiàng)目的build path,全程自動(dòng)化處理,真是爽啊。

          7. 為nexus增加新的proxy  repository
                  方法很簡單,administration -> Repositories -> add -> proxy,填寫后保存即可。但是要注意,nexus不會(huì)自動(dòng)將新加入的repository添加到group中,而我們一般喜歡直接使用默認(rèn)的"public repository" group, 比如前面我在maven的profile中就只設(shè)置了這一個(gè)URL: http://localhost:8081/nexus/content/groups/public。因此需要手工修改"public repository" group的設(shè)置,將剛才添加的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/
                                  加入這個(gè)純粹是因?yàn)樗衧un的jmxri/jmxtools這些Artifact,強(qiáng)烈鄙視sun,自己的官方repository居然沒有。
          8. 總結(jié)
              很明顯,nexus無論是在界面,功能,操作上,都比artifactory強(qiáng)大的多。
              因此推薦大家使用nexus替代artifactory作為maven私服。
             
          updates:
          1.  2008.11.28 
          由于公司升級操作系統(tǒng),告別老舊不堪的windows2000升級到vista,因此重新安裝了nexus. 新版本的nexus似乎增加了不少小的功能比如對remote index的支持,具體沒有深究,不過能不斷更新實(shí)在是很令人欣慰。以后就打算用nexus了。
             
          posted on 2009-01-05 23:26 禮物 閱讀(1914) 評論(1)  編輯  收藏 所屬分類: Maven2

          評論

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

          主站蜘蛛池模板: 北辰区| 汽车| 梅州市| 满洲里市| 都江堰市| 宜丰县| 麦盖提县| 林州市| 交口县| 肇州县| 衡阳市| 通道| 通化市| 新余市| 老河口市| 临海市| 东台市| 芜湖县| 渑池县| 黎城县| 巧家县| 诸城市| 苏尼特右旗| 舟山市| 青铜峡市| 安仁县| 清河县| 上思县| 卫辉市| 大荔县| 清徐县| 柳江县| 屯门区| 梨树县| 化州市| 江孜县| 彰武县| 三明市| 柳州市| 毕节市| 兴业县|