1. 程式人生 > >nexus的安裝和簡介(3)

nexus的安裝和簡介(3)

從私服下載jar 

沒有配置nexus之前,如果本地倉庫沒有,去中央倉庫下載,通常在企業中會在區域網內部署一臺私服伺服器,有了私服本地專案首先去本地倉庫找jar,如果沒有找到則連線私服從私服下載jar包,如果私服沒有jar包私服同時作為代理伺服器從中央倉庫下載jar包,這樣做的好處是一方面由私服對公司專案的依賴jar包統一管理,一方面提高下載速度,專案連線私服下載jar包的速度要比專案連線中央倉庫的速度快的多。

 

本例子測試從私服下載dao 工程jar包。

管理倉庫組

nexus中包括很多倉庫,hosted中存放的是企業自己釋出的jar包及第三方公司的jar包,

proxy中存放的是中央倉庫的jar,為了方便從私服下載jar包可以將多個倉庫組成一個倉庫組,每個工程需要連線私服的倉庫組下載jar包。

 

開啟nexus配置倉庫組,如下圖:

 

 

 

上圖中倉庫組包括了本地倉庫、代理倉庫等。

 

setting.xml中配置倉庫

在客戶端的setting.xml中配置私服的倉庫,由於setting.xml中沒有repositories的配置標籤需要使用profile定義倉庫。

 

<profile>   

<!--profileid-->

   <id>dev</id>   

    <repositories>   

      <repository>  

<!--倉庫idrepositories可以配置多個倉庫,保證id不重複-->

        <id>nexus</id>   

<!--倉庫地址,即nexus倉庫組的地址-->

        <url>http://localhost:8081/nexus/content/groups/public/</url>   

<!--是否下載releases構件-->

        <releases>   

          <enabled>true</enabled>   

        </releases>   

<!--是否下載snapshots構件-->

        <snapshots>   

          <enabled>true</enabled>   

        </snapshots>   

      </repository>   

    </repositories>  

 <pluginRepositories>  

     <!-- 外掛倉庫,maven的執行依賴外掛,也需要從私服下載外掛 -->

        <pluginRepository>  

         <!-- 外掛倉庫的id不允許重複,如果重複後邊配置會覆蓋前邊 -->

            <id>public</id>  

            <name>Public Repositories</name>  

            <url>http://localhost:8081/nexus/content/groups/public/</url>  

        </pluginRepository>  

    </pluginRepositories>  

  </profile>  

 

使用profile定義倉庫需要啟用才可生效。

 

  <activeProfiles>

    <activeProfile>dev</activeProfile>

  </activeProfiles>