一、倉庫定義
用來存儲全部maven共享構建的位置java
二、倉庫佈局
根據maven座標定義每一個構建在倉庫中的存儲路徑,大體爲:groupId/artifactId/versionId/artifactId-version.packagingshell
三、倉庫分類
1)、本地倉庫瀏覽器
位置:~/.m2/resposity(一個用戶只有一個本地倉庫)架構
2)、遠程倉庫maven
中央倉庫:Maven默認的遠程倉庫(http://repo1.maven.org/maven2)佈局
私服:特殊的遠程倉庫,架設在局域網內url
鏡像:代替中央倉庫,速度通常比中央倉庫快spa
四、私服
Nexus架構:日誌
Nexus 安裝code
1)、從http://nexus.sonatype.org/downloads 下載nexus(注:nexus是典型的javaWeb應用,分兩種安裝包,一種是包含Jetty容器的Budle包,另外一種是不包含Web容器的war包。此處以Bundle爲例進行講解)
2)、解壓Budle包,創建軟鏈接(方便nexus升級)
$ sudo cp nexus-latest-bundle.tar.gz /usr/local $ cd /usr/local $ sudo tar -zxvf nexus-latest-bundle.tar.gz $ sudo ln -s nexus-2.8.1-01/ nexus
注:解壓完以後會獲得兩個子目錄,nexus-2.8.1-01 和 sonatype-work,前者包含Nexus運行所須要的文件,如啓動腳本、依賴jar包等,後者包含Nexus生成的配置文件、日誌文件、倉庫文件等。第一個目錄是運行所必須的,並且全部相同版本所包含的該目錄是相同的,而第二個目錄不是必須的,Nexus會在運行的時候動態建立該目錄,不過他的內容對於各個Nexus實例是不同的,由於不一樣用戶在不一樣機器上使用的Nexus會有不一樣的配置和倉庫內容,所以備份的時候僅備份該目錄便可(它包含了用戶的特定內容)
3)、配置環境變量NEXUS_HOME
4)、啓動nexus
$ cd /usr/local/nexus $ ./bin/nexus start
注:若是配置好了NEXUS_HOME/bin到PATH中,則此處能夠直接使用以下命令:
$ nexus start
注:啓動時候若因爲端口衝突形成失敗,則能夠到 /usr/local/nexus-2.8.1-01/conf/nexus.properties 文件中修改端口參數
安裝完成以後,在瀏覽器中輸入:http://localhost:8081/nexus ,若出現如下界面表示安裝成功
配置構建從私服下載
打開./m2/setting.xml文件
找到mirrors,添加若是代碼:
<mirror>
<!--此處配置全部的構建均從私有倉庫中下載 *表明全部,也能夠寫central -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://192.168.1.100:8000/nexus/content/groups/public</url>
</mirror>
找到profiles,添加以下代碼:
<profile>
<id>nexus</id>
<!—全部請求均經過鏡像 -->
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
找到activeProfiles,添加以下代碼激活profile
<activeProfile>nexus</activeProfile>
部署構建到Nexus
在項目的pom.xml中配置
<distributionManagement>
<repository>
<id>releases</id>
<name>Internal Releases</name>
<url>http://localhost:8000/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>Internal Snapshots</name>
<url>http://localhost:8000/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
並在~/.m2/setting文件中找到servers,添加:
<!-- 設置發佈時的用戶名 -->
<servers>
<server>
<id> releases </id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id> snapshots </id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>