配置Maven的 本地倉庫 和 遠端倉庫(私服)
阿新 • • 發佈:2018-12-12
maven中並沒有我們開發所需的jar包,只是存有jar包的座標,jar包是存於本地倉庫/遠端倉庫/中央倉庫中的。當我們啟動maven工程時,專案會根據maven中的座標去查詢對應的jar包。
- 查詢maven工程中存放座標的配置檔案:開啟maven的安裝路檔案,在conf資料夾下有一個settings.xml的檔案。這裡面存的就是maven工程的一些配置檔案,包括本地倉庫、私服… 。
- 預設情況下,首次安裝maven後的本地倉庫是存於系統盤下的*.m2/repository*資料夾中 。
- 如果首次啟動maven工程後本地倉庫中沒有jar檔案,而且沒有配置遠端倉庫。則在聯網狀態下會直接到中央倉庫中下載,這會很麻煩(伺服器在國外下載很慢,所有有了後面的“遠端倉庫“”)。沒有網路則直接報錯。
- 遠端倉庫。 如果在settings中配置了遠端倉庫的情況下,並且遠端倉庫和本地倉庫處於同一區域網中。當在本地倉庫中找不到需要的jar包,則就會先去遠端倉庫中查詢。如果找到,則下載並存入本地倉庫中;如果沒找到,則又會到中央倉庫中下載並存入本地倉庫中,或者可以直接從本地上傳jar包到遠端倉庫。
由於maven工程預設的本地倉庫是在系統盤,這對於電腦的影響很大。所以我們需要重新配置本地倉庫
**
配置本地倉庫:
**
- 找到一個“本地倉庫”的壓縮包,這裡面已經有了很多常用的jar包。然後解壓到一個沒有中文,沒有空格的路徑下即可。比如:F:\maven_repository
- 到maven工程的conf–>settings檔案中配置:
把本地倉庫的路徑複製到標籤內即可
**
配置遠端倉庫:
** 這裡配置阿里雲的遠端倉庫 在settings.xml檔案中新增下面內容即可
<mirrors> <mirror> <id>nexus-aliyun</id> <mirrorOf>*</mirrorOf> <name>Nexus aliyun</name> <url>http://maven.aliyun.com/nexus/content/groups/public</url> </mirror> </mirrors> <profiles> <profile> <repositories> <repository> <id>nexus</id> <name>local private nexus</name> <url>http://mvnrepo.tae.taobao.com/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>nexus</id> <name>local private nexus</name> <url>http://mvnrepo.tae.taobao.com/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles>