Ubuntu server下搭建Maven私服Nexus


 

  Ubuntu server下搭建Maven私服Nexus

  Maven私服Nexus的作用,主要是為了節省資源,在內部作為maven開發資源共享服務器來使用。

  

  1、下載

  通過root用戶進去Ubuntu server

  $  cd /opt

  $  wget http://download.sonatype.com/nexus/oss/nexus-2.10.0-02-bundle.tar.gz

  

  2、啟動

  環境准備,啟動nexus,必須先完成JDK環境的配置。

  $  cd /opt/

  $  tar -zxvf nexus-2.10.0-02-bundle.tar.gz

  $  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

 

  3、配置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倉庫了。

 

  4、遠程測試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>

  新建項目,構建並測試

  

  5、三方jar包入maven私服

  比如 有些第三方jar包,在maven中心倉庫沒有,這個時候就需要手動在本地將jar上傳上去,以供本地其他用戶使用,簡單截圖介紹

  

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM