Nexus私服安裝html
第一步:下載nexus.war包,而後拷貝到tomcat下的webapps目錄中web
第二步:啓動tomcatapache
第三步:訪問http://localhost:8080/nexus-2.7.0-06/index.html#welcome顯示以下:瀏覽器
第四步:點擊右上角「log in」 ,輸入username:admin 和Password:admin123登陸緩存
第五步:登陸成功tomcat
第六步:點擊Views/Repositories 中Repositoriesoracle
Nexus內置倉庫說明:app
(1)Maven Central:該倉庫代理Maven中央倉庫,其策略爲Release,所以只會下載和緩存中央倉庫中的發佈版本構件。webapp
(2)Releases:這是一種策略爲Release的宿主類型倉庫,用來部署組織內部的發佈版本構件。maven
(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搜索)
第十步:配置全部構建均從私服下載,在~/.m2/setting.xml中配置以下:
<settings>
<mirrors>
<mirror>
<!--此處配置全部的構建均從私有倉庫中下載 *表明全部,也能夠寫central -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://192.168.1.100:8000/nexus/content/groups/public</url>
</mirror>
</mirrors>
<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>
</profiles>
<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
第十一步:部署構建到Nexus,包含Release和Snapshot, 在項目根目錄中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>
第十二步:Nexus的訪問權限控制,在~/m2/setting.xml中配置以下:
<!-- 設置發佈時的用戶名 -->
<servers>
<server>
<id> releases </id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id> snapshots </id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
私服是架設在局域網的一種特殊的遠程倉庫,目的是代理遠程倉庫及部署第三方構件。有了私服以後,當 Maven 須要下載構件時,直接請求私服,私服上存在則下載到本地倉庫;不然,私服請求外部的遠程倉庫,將構件下載到私服,再提供給本地倉庫下載。
咱們可使用專門的 Maven 倉庫管理軟件來搭建私服,好比:Apache Archiva,Artifactory,Sonatype Nexus。這裏咱們使用 Sonatype Nexus。
2 . 安裝Nexus
2 . 1 . 下載Nexus
Nexus 專業版是須要付費的,這裏咱們下載開源版 Nexus OSS。Nexus 提供兩種安裝包,一種是包含 Jetty 容器的 bundle 包,另外一種是不包含容器的 war 包。下載地址:http://www.sonatype.org/nexus/go。
2 . 2 . 使用bundle安裝包安裝Nexus
解壓安裝包nexus-2.8.1-bundle.zip,打開命令提示符,進入/nexus-2.8.1-01目錄,鍵入nexus命令(爲方便啓動和退出Nexus,可將bin目錄添加到環境變量):
執行 nexus install 將Nexus安裝爲Windows服務。可將服務啓動方式設爲手動,之後經過 nexus start 便可啓動Nexus ,經過 nexus stop 退出Nexus:
打開瀏覽器,訪問:http://localhost:8081/nexus/ (Jetty 默認端口號:8081):
點擊右上角 Log In,使用用戶名:admin ,密碼:admin123 登陸,可以使用更多功能:
3 . Nexus預置的倉庫
點擊左側 Repositories 連接,查看 Nexus 內置的倉庫:
Nexus 的倉庫分爲這麼幾類:
hosted 宿主倉庫:主要用於部署沒法從公共倉庫獲取的構件(如 oracle 的 JDBC 驅動)以及本身或第三方的項目構件;
proxy 代理倉庫:代理公共的遠程倉庫;
virtual 虛擬倉庫:用於適配 Maven 1;
group 倉庫組:Nexus 經過倉庫組的概念統一管理多個倉庫,這樣咱們在項目中直接請求倉庫組便可請求到倉庫組管理的多個倉庫。
4 . 添加代理倉庫
以 Sonatype 爲例,添加一個代理倉庫,用於代理 Sonatype 的公共遠程倉庫。點擊菜單 Add - Proxy Repository :
填寫Repository ID - sonatype;Repository Name - Sonatype Repository;
Remote Storage Location - http://repository.sonatype.org/content/groups/public/ ,save 保存:
將添加的 Sonatype 代理倉庫加入 Public Repositories 倉庫組。選中 Public Repositories,在 Configuration 選項卡中,將 Sonatype Repository 從右側 Available Repositories 移到左側 Ordered Group Repositories,save 保存:
5 . 搜索構件
爲了更好的使用 Nexus 的搜索,咱們能夠設置全部 proxy 倉庫的 Download Remote Indexes 爲 true,即容許下載遠程倉庫索引。
索引下載成功以後,在 Browse Index 選項卡下,能夠瀏覽到全部已被索引的構件信息,包括座標、格式、Maven 依賴的 xml 代碼:
有了索引,咱們就能夠搜索了:
6 . 配置Maven使用私服
私服搭建成功,咱們就能夠配置 Maven 使用私服,之後下載構件、部署構件,都經過私服來管理。
在 settings.xml 文件中,爲全部倉庫配置一個鏡像倉庫,鏡像倉庫的地址即私服的地址(這兒咱們使用私服公共倉庫組 Public Repositories 的地址):