天天看點

【連載】Maven系列(四)——配置私服

相關文章

1.《用起來超爽的Maven——入門篇》

2.《用起來超爽的Maven——進階篇》

3.《Maven系列(三) 進階》

一、為什麼需要私服  

有些公司并不提供外網給程式員,是以不能使用maven通路遠端的倉庫位址,是以很有必要在區域網路裡找一台有外網權限的機器;搭建nexus私服,然後程式員連到這台私服上,這樣的話就可以通過這台搭建了nexus私服的電腦通路maven的遠端倉庫。

二、配置步驟

第一步:下載下傳nexus-2.6.4-02.war包,然後拷貝到tomcat下的webapps目錄中

http://www.sonatype.org/nexus/go     Download the Nexus WAR distribution

第二步:啟動tomcat

第三步:通路http://localhost:8088/nexus-2.6.4-02顯示如下:

第四步:點選右上角“log in” ,輸入username:admin 和Password:admin123登入

第五步:登入成功

第六步:點選Views/Repositories 中Repositories

Nexus内置倉庫說明:

(1)Maven Central:該倉庫代理Maven中央倉庫,其政策為Release,是以隻會下載下傳和緩存中央倉庫中的釋出版本構件。

(2)Releases:這是一種政策為Release的宿主類型倉庫,用來部署組織内部的釋出版本構件。

(3)Snapshots:這是一個政策為Snapshot的宿主類型倉庫,用來部署組織内部的快照版本構件。

(4)3rd party:這是一個政策為Release的宿主類型倉庫,用來部署無法從公共倉庫獲得的第三方釋出版本構件。

(5)Public Repositories:該倉庫組将上述所有政策為Release的倉庫聚合并通過一緻的位址提供服務。

第七步:建立宿主目錄和代理倉庫

Hosted:本地倉庫,通常我們會部署自己的構件到這一類型的倉庫。 包括3rd party倉庫,Releases倉庫,Snapshots倉庫

Proxy:代理倉庫,它們被用來代理遠端的公共倉庫,如maven中央倉庫。 

Group:倉庫組,用來合并多個hosted/proxy倉庫,通常我們配置maven依賴倉庫組。 

第八步:建立倉庫組

點選Public Repositories倉庫,在Configurations欄中選取需要合并的倉庫,點選箭頭加到左邊儲存即可

第九步:下載下傳Index索引并進行建構搜尋(GAV搜尋)

點選Views/Repositories菜單下面的Repositories,将這三個倉庫 Apache Snapshots,Codehaus Snapshots,Central的Download Remote Indexes修改為 true。然後在這三個倉庫上分别右鍵,選擇Repari index,這樣Nexus就會去下載下傳遠端的索引檔案。

第十步:配置所有建構均從私服下載下傳,在~/.m2/setting.xml中配置如下:

<settings>

 <mirrors>

 <mirror>

 <!--此處配置所有的建構均從私有倉庫中下載下傳 *代表所有,也可以寫central -->

 <id>nexus</id>

 <mirrorOf>*</mirrorOf>

 <url>http://localhost:8088/nexus-2.6.4-02/content/groups/public</url>

 </mirror>

 </mirrors>

 <profiles>

 <profile>

<id>nexus</id>

<repositories>

<repository>

<name>local private nexus</name>

<url>http://localhost:8088/nexus-2.6.4-02/content/groups/public</url>

</repository>

</repositories>

</profile>

<profile>

<id>nexus-snapshots</id>

<name>local private nexus snapshots</name>

<url>http://localhost:8088/nexus-2.6.4-02/content/groups/public-snapshots</url>

 </profiles>

<activeProfiles>

 <!--make the profile active all the time -->

 <activeProfile>nexus</activeProfile>

 </activeProfiles>

第十一步:Nexus的通路權限控制,在~/m2/setting.xml中配置如下:

<!-- 設定釋出時的使用者名 -->

 <servers>

  <server>

  <id> releases </id>

<username>admin</username>

<password>admin123</password>

</server>

<server>

<id> snapshots </id>

 </server>

 </servers>

第十二步:

部署建構到Nexus,包含Release和Snapshot, 在項目根目錄中pom.xml中配置:

<distributionManagement> 

<repository> 

    <id>releases</id> 

    <name>Internal Releases</name> 

    <url>http://localhost:8088/nexus-2.6.4-02/content/repositories/releases/</url> 

</repository> 

<snapshotRepository> 

    <id>snapshots</id> 

    <name>Internal Snapshots</name> 

    <url>http://localhost:8088/nexus-2.6.4-02/content/repositories/snapshots/</url> 

</snapshotRepository> 

  </distributionManagement>

第十三步:pom.xml

你還在等什麼,趕快試試吧。

關注作者