Maven的本地倉庫、中心倉庫、私服(NEW)

本地倉庫javascript

設置本地倉庫到指定目錄,而不使用Maven默認的配置(默認放在C:/user/m2.目錄下)java

打開Maven的解壓目錄E:\soft\apache-maven-3.1.0\conf,修改settings.xml數據庫

配置localRepository便可完成本地倉庫的設置:apache

Xml代碼 服務器

 收藏代碼

  1. <localRepository>E:/repository/maven/repos</localRepository>  

 

==================================================================網絡

 

中心倉庫oracle

即,告訴Maven從外網的哪一個地方下載jar包app

Maven的安裝目錄中,在lib目錄下,maven-model-builder-3.1.0.jar中,有一個默認的pom.xml文件maven

其中就配置了Maven默認鏈接的中心倉庫ui

修改中心倉庫:

直接在POM.xml中加入repository的配置,指定一個新的url便可

注意:這裏仍然使用<id>central</id>,目的在於覆蓋Maven中的配置的id爲central的repository!

Xml代碼 

 收藏代碼

  1. <repositories>  
  2.     <repository>  
  3.         <id>central</id>  
  4.         <name>My Central Repository</name>  
  5.         <url>http://repo.maven.apache.org/maven2</url>  
  6.         <layout>default</layout>  
  7.         <snapshots>  
  8.             <enabled>false</enabled>  
  9.         </snapshots>  
  10.     </repository>  
  11. </repositories>  

 

==================================================================

 

 私服

配置在局域網環境中,爲局域網中全部開發人員提供jar包的統一管理

本地倉庫(本機)--->私服(局域網)--->中心倉庫(外部網絡)

 

私服的安裝

1.下載NEXUS,http://www.sonatype.org

2.解壓

3.配置環境變量:

新建環境變量:NEXUS_HOME = E:\soft\nexus-2.5.1-01

加入到path中:%NEXUS_HOME%\bin;

4.打開CMD命令行

C:\Users\Administrator>nexus install      安裝服務

C:\Users\Administrator>nexus start         啓動服務

C:\Users\Administrator>nexus uninstall  卸載服務

5.訪問私服

使用默認帳戶:admin 密碼:admin123

NEXUS內部使用Jetty做爲服務器

 http://localhost:8081/nexus   【界面用extjs開發的】

 

倉庫的分類

查看Repository

 

host倉庫--->內部項目的發佈倉庫

Snapshots   發佈內部snapshots版本的倉庫

Releases     發佈內部release版本的倉庫

3rd party      發佈第3方jar包的倉庫,如oracle數據庫驅動,open-189.jar

 

proxy倉庫--->從遠程中心倉庫查找jar包的倉庫

Apache Snapshots    查找Apache項目的快照版本的倉庫

Central   中心倉庫http://repo1.maven.org/maven2/

Codehaus Snapshots    查找Codehaus 的快照版本的倉庫

 

group倉庫--->把倉庫按組劃分,以組爲單位進行管理

 

virtual倉庫  

 

私服的配置 / Repository的配置

在parent模塊的pom.xml中加入私服的配置,讓Maven從私服下載jar包,而不直接去遠程倉庫下載。

默認狀況下,Maven下載jar包將直接鏈接到外網http://repo1.maven.org/maven2/去下載;

安裝私服以後,讓Maven下載jar包先從私服查找,若是沒有,再從外網下載並保存在私服上

在POM在加入下面的配置,其中url爲NEXUS私服的Public Repository對外的地址

之後,Maven下載構建(jar包或插件)都將從這裏開始下載

Xml代碼 

 收藏代碼

  1. <project>  
  2.     
  3.   ...  
  4.     
  5.   <!-- 配置私服地址 -->  
  6.   <repositories>  
  7.     <repository>  
  8.       <id>nexus</id>  
  9.       <url>http://localhost:8081/nexus/content/groups/public/</url>  
  10.       <snapshots><enabled>true</enabled></snapshots>  
  11.       <releases><enabled>true</enabled></releases>  
  12.     </repository>  
  13.   </repositories>  
  14.   <pluginRepositories>  
  15.     <pluginRepository>  
  16.       <id>nexus</id>  
  17.       <url>http://localhost:8081/nexus/content/groups/public/</url>  
  18.       <snapshots><enabled>true</enabled></snapshots>  
  19.       <releases><enabled>true</enabled></releases>  
  20.     </pluginRepository>  
  21.   </pluginRepositories>  
  22.   
  23.   ...  
  24.   
  25. <project>  

 

經過settings.xml來配置私服

因爲全部的Maven項目都會用settings.xml中的配置進行解析,若是將Repository配置到這個文件中,那麼對全部的Maven項目都將生效。

此時,Maven項目中的POM文件就不須要再配置私服地址了!

注意:修改settings.xml文件時,看IDE中關聯的是哪一個settings文件。

如C:\user\.m2目錄下可能存在,Maven的解壓目錄下也存在,具體修改哪一個根據實際狀況而定。如,Eclipse下,查看Maven的User Settings選項即能看到關聯。

個人IDE關聯的是Maven\conf目錄下的settings.xml:

E:\soft\apache-maven-3.1.0\conf\settings.xml

首先,經過<profile/>添加Repository和pluginRepository

Xml代碼 

 收藏代碼

  1. <settings>  
  2.   
  3.   ...  
  4.   
  5.   <profiles>  
  6.      <profile>  
  7.       <id>profile-nexus</id>  
  8.   
  9.       <repositories>  
  10.         <repository>  
  11.           <id>nexus</id>  
  12.           <url>http://localhost:8081/nexus/content/groups/public/</url>  
  13.           <snapshots><enabled>true</enabled></snapshots>  
  14.           <releases><enabled>true</enabled></releases>  
  15.         </repository>  
  16.       </repositories>  
  17.       <pluginRepositories>  
  18.         <pluginRepository>  
  19.           <id>nexus</id>  
  20.           <url>http://localhost:8081/nexus/content/groups/public/</url>  
  21.           <snapshots><enabled>true</enabled></snapshots>  
  22.           <releases><enabled>true</enabled></releases>  
  23.         </pluginRepository>  
  24.       </pluginRepositories>  
  25.     </profile>  
  26.   </profiles>  
  27.   
  28.   ...  
  29.   
  30. </settings>  

 

而後,使用<activeProfiles>對上面的配置進行激活(經過配置的id標識進行激活)

 Xml代碼 

 收藏代碼

  1. <activeProfiles>  
  2.   <activeProfile>profile-nexus</activeProfile>  
  3. </activeProfiles>  

 

 

如今,本地機器上建立Maven項目,都會使用settings中有關倉庫的配置了

本地倉庫:

<localRepository>E:/repository/maven/repos</localRepository>

本地Maven下載的依賴包和插件都將放到E:/repository/maven/repos目錄中

私服:

本地全部Maven項目,下載構建都統一從http://localhost:8081/nexus/content/groups/public/ 下載!

【私服上不存在某個構建時,再從遠程下載】

遠程倉庫:

若是遠程倉庫鏈接不上,則經過nexus修改central的地址便可!

當前使用Maven的默認配置:http://repo1.maven.org/maven2/

相關文章
相關標籤/搜索