Maven倉庫的分類和配置

1.Maven倉庫的分類

Maven倉庫可以分爲本地倉庫遠程倉庫兩類

1.1【本地倉庫】

本地倉庫相當於一個緩存,在電腦上是一個文件夾,我們可以設置這個文件夾的路徑(具體怎麼設置會在下面的配置體現),工程第一次需要某種jar包時,會從遠程倉庫(互聯網)下載並保存到本地倉庫中(在程序員的電腦上),當第二次使用時,不需要去遠程倉庫下載,會先去本地倉庫中找,如果找不到纔會去遠程倉庫上下載。

1.2【遠程倉庫】

遠程倉庫又分爲中央倉庫私服兩類

1.2.1【中央倉庫】

中央倉庫中的jar包由專業團隊(Maven團隊)維護,中央倉庫中存放了全世界大多數流行的開源軟件的jar包,是Maven默認的遠程倉庫

1.2.2【私服】

在公司內部架設一臺服務器,裏面存放了所有需要的jar包,對外公開,供終端下載。例如阿里雲

 

2.Maven倉庫的配置

2.1Maven配置本地倉庫

修改安裝Maven的路徑下的config文件下的setting.xml文件的localReporsity標籤(我下載的這個版本是在50多行)

<localRepository>自己設置本地倉庫的路徑</localRepository>

我設置到了D:\maven\repository

  <!-- localRepository
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ${user.home}/.m2/repository
  <localRepository>/path/to/local/repo</localRepository>
  -->
<localRepository>D:\maven\repository</localRepository>

 

2.2Maven配置遠程倉庫鏡像

Maven默認的遠程倉庫是Maven團隊維護的中央倉庫,由於網絡原因,去中央倉庫下載jar包需要到國外的網站,不太便捷,速度慢,於是我們可以選擇把國內的阿里雲的Maven倉庫作爲中央倉庫鏡像

修改安裝Maven的路徑下的config文件下的setting.xml文件的mirrors標籤(我下載的這個版本是在50多行)

 <mirror>  
          <id>alimaven</id>  
          <mirrorOf>central</mirrorOf>  
          <name>aliyun maven</name>        
          <url>http://maven.aliyun.com/nexus/content/groups/public/</url>  
    </mirror>

其中各個標籤的含義是:

id:當前鏡像的唯一標識

mirrorOf:將哪個遠程倉庫當做中央倉庫鏡像,中央倉庫的id是central,所以將阿里雲的Maven倉庫設置爲中央倉庫鏡像時,其值必須設置爲central

name:爲當前的中央倉庫鏡像起一個名字,便於開發者閱讀

url:阿里雲Maven倉庫的地址

 

<mirrors>
    <!-- mirror
     | Specifies a repository mirror site to use instead of a given repository. The repository that
     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
     |
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>
     -->
	 <mirror>  
          <id>alimaven</id>  
	      <mirrorOf>central</mirrorOf>  
          <name>aliyun maven</name>        
          <url>http://maven.aliyun.com/nexus/content/groups/public/</url>  
    </mirror>
  </mirrors>

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章