1. 程式人生 > >精簡nexus私服搭建

精簡nexus私服搭建

  maven對專案原始碼和依賴管理的好處不言而喻,不過所依賴倉庫都是外網那些常用提供的倉庫地址,基於安全,當外網環境有限制,或私有共通jar需共享時,則會需要搭建內部私服,以下說明基於Linux環境。

  1. maven 安裝   安裝很簡單,主要就幾個步驟和設定。

  a.  wget 安裝包下載地址;   b.  tar zxvf 壓縮的安裝包 (如果需要安裝到指定位置將包移動 : mv  源路徑  目的地址; );  

  c. 配置環境變數   編輯 vi /etc/profile  且增加  export MAVEN_HOME=解壓路徑 與 export PATH=$PATH:$MAVEN_HOME/bin  d. 配置生效  source /etc/profile   e.驗證 mvn -v。

  2. 安裝nexus  (據說不提倡用 nexus3.x 以上版本,用nexus2.x版本 , JDK版本1.7以上)

  a. 下載nexus2.x 安裝包 b. 解壓  tar  zxvf   安裝包;   c.  如改埠在  /conf/nexus.properties  d.  啟動執行 切到  cd nexus-2.x/bin  再執行  ./nexus  start

  e. 訪問  http://xxx.xxx.xxx.xx:8081/nexus/

   預設 admin/admin123  (如果啟動要root許可權 用 sudo sh nexus  start啟動 )

  3. 私服倉庫使用及管理 

  a. 登入進去,nexus預設會有已建立的常用倉庫分類,含 snapshots:開發過程中的版本倉庫  release:正式釋出的版本倉庫  public:maven主庫  3rd party,存第三方的jar

  b. maven setting.xml設定  (注意 兩個xml  對應 id保持一致 )

  <servers>

<server>
    <id>releases</id>
        <username>admin</username>
    <password>admin123</password>
</server>
<server>
     <id>snapshots</id>
        <username>admin</username>
     <password>admin123</password>    
</server>       
                       
<server>
        <id>public</id>
        <username>admin</username>
        <password>admin123</password>
</server>
</servers>

  c. maven pom.xml設定 

   <groupId> News_Recommend</groupId>
   <artifactId> News_Recommend</artifactId>
   <version> 0.0.1-SNAPSHOT</version>
   <packaging> jar</packaging>

<!-- 設定主倉庫 -->
<repositories>
<!-- nexus私服 -->
<repository>
<id> public</id>
<url> http://xxxx:8081/nexus/content/groups/public/ </url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
 
<!-- 自動打包 -->
    <distributionManagement>
        <repository>
            <id>releases</id>
            < url> http://xxxx:8081/nexus/content/repositories/releases </url >
        </repository>
        <snapshotRepository>
            <id>snapshots </id>
            <url> http://xxxx:8081/nexus/content/repositories/snapshots </url >
        </snapshotRepository >
    </distributionManagement >

  d. 打成jar上傳私服  工程右鍵-->run as-->run configuration   進入 nexus後臺可看到上傳的jar , 如要release版本  <version> 0.0.1-SNAPSHOT</version> 改   <version> 0.0.1</version>

  

  參考 http://www.cnblogs.com/zhongshengzhen/p/nexus_maven.html