Ubuntu server下搭建Maven私服Nexus服務器
Maven私服Nexus的做用,主要是爲了節省資源,在內部做爲maven開發資源共享服務器來使用。maven
一、下載測試
經過root用戶進去Ubuntu serverthis
$ cd /opturl
$ wget http://download.sonatype.com/nexus/oss/nexus-2.10.0-02-bundle.tar.gzspa
二、啓動代理
環境準備,啓動nexus,必須先完成JDK環境的配置。code
$ cd /opt/server
$ tar -zxvf nexus-2.10.0-02-bundle.tar.gzxml
$ cd /opt/nexus-2.10.0-02/bin
$ vi nexus
在啓動文件nexus中增長nexus的啓動用戶,不然沒權限啓動,將報錯以下:
WARNING - NOT RECOMMENDED TO RUN AS ROOT
If you insist running as root, then set the environment variable RUN_AS_USER=root before running this script
因此要解決此問題,須要在啓動文件nexus,加上RUN_AS_USER=root,如圖所示
保存退出以後,便可啓動nexus,命令以下:
$ ./nexus start
Starting Nexus OSS...
Started Nexus OSS.
表示啓動成功,訪問地址:http://ip:8081/nexus
三、配置nexus
登陸nexus,右上角Log In,默認登陸用戶名密碼:admin/admin123
登陸以後,咱們能夠點擊左邊菜單欄Repositories進入詳細配置
能夠本身從新建立一個私服配置,這裏咱們用系統在帶的Public Repositories
關於倉庫的類型介紹
hosted 類型的倉庫,內部項目的發佈倉庫
releases 內部的模塊中release模塊的發佈倉庫
snapshots 發佈內部的SNAPSHOT模塊的倉庫
3rd party 第三方依賴的倉庫,這個數據一般是由內部人員自行下載以後發佈上去
proxy 類型的倉庫,從遠程中央倉庫中尋找數據的倉庫
group 類型的倉庫,組倉庫用來方便咱們開發人員進行設置的倉庫
可是須要將其餘幾個代理的庫配置映射到Public中,分別將Apache Snapshots、Central、Codehaus Sanpshots下Download Remote Indexes選項選擇【true】,保存便可,默認是false,以下圖
把將類型爲Proxy的庫Apache Snapshots、Central、Codehaus Sanpshots配置到Public Repositories下,以下圖:
而後分別將Apache Snapshots、Central、Codehaus Sanpshots更新Index,在每個庫上面右鍵操做Repair Index
最後將Public Repositories操做Repair Index
而後接能夠測試maven倉庫了。
四、遠程測試maven倉庫
在項目中,引用maven倉庫。則須要項目的pom.xml文件中添加以下:
<repositories> <repository> <snapshots> <enabled>true</enabled> </snapshots> <id>Public</id> <name>Public Repositories</name> <url>http://192.168.10.50:8081/nexus/content/groups/public/</url> </repository> </repositories>
而後執行maven下載依賴jar,檢測是否下載成功~在私服上,經過左邊的Artifact Search 搜索窗口,查看jar包是否在私服下載成功。
另外,一般咱們是修改本地的maven安裝目錄下的配置文件setting.xml,將本地倉庫更換成私服倉庫地址,保證本客戶端上全部的項目都將使用私服,配置setting.xml以下:
在<profiles></profiles>加入
<profile>
<id>env-dev</id>
<repositories>
<repository>
<id>Public</id>
<name>Public Repositories</name>
<url>http://192.168.10.50:8081/nexus/content/groups/public</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
</profile>
並在</profiles>以後中加入
<activeProfiles> <activeProfile>env-dev</activeProfile> </activeProfiles>
新建項目,構建並測試
五、三方jar包入maven私服
好比 有些第三方jar包,在maven中心倉庫沒有,這個時候就須要手動在本地將jar上傳上去,以供本地其餘用戶使用,簡單截圖介紹