<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<mirrors>
<!-- 阿里雲倉庫,使用國內maven 資源庫 -->
<mirror>
<id>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
</mirror>
<!-- 中央倉庫1 -->
<mirror>
<id>repo1</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://repo1.maven.org/maven2/</url>
</mirror>
<!-- 中央倉庫2 -->
<mirror>
<id>repo2</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://repo2.maven.org/maven2/</url>
</mirror>
</mirrors>
</settings>
eclipse設置maven加載國內鏡像
使用maven包管理器開發java web時,由於國內網速太慢,或者牆的緣故,創建project后,總是要等待很長時間加載所需jar包。這對於開發者而言,是一種痛苦的等待,對於企業,也是一種損失。
今天得遇高人指點,對eclipse中的maven插件做了優化配置,下面一步一步的操作示范,幫助有需要的朋友們:
linux/windows:打開eclipse后,window-》preferences-》maven
mac:eclipse偏好設置-》maven
然后選擇 User Settings,如下圖:
根據圖中3的指示的位置,創建一個配置文件settings.xml。
linux/mac均可使用下面命令創建,先不寫任何內容,然后保存,vim命令模式下是:wq,注:w是寫入,q是退出,冒號是命令開始
~$ vim /home/joyven/.m2/settings.xml
windows需要在當前用戶目錄下,依管理員身份創建。
接着回到eclipse的操作步驟,先關閉preferences面板,再次根據前面說步驟的,打開此面板,你會看到User Settings中發生的變化,如下圖:
是的,你沒看錯,多出來了一個openfile。點擊openfile,然后Apply,再OK,最后關閉此面板。此時,已經在eclipse編輯窗口打開了前面創建的settings.xml文件。
配置開始了,將下面的代碼復制到settings.xml文件中,保存即可。
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <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>nexus-osc</id> <mirrorOf>central</mirrorOf> <name>Nexus osc</name> <url>http://maven.oschina.net/content/groups/public/</url> </mirror> <mirror> <id>nexus-osc-thirdparty</id> <mirrorOf>thirdparty</mirrorOf> <name>Nexus osc thirdparty</name> <url>http://maven.oschina.net/content/repositories/thirdparty/</url> </mirror> </mirrors> <profiles> <profile> <id>default</id> <repositories> <repository> <id>nexus</id> <name>local private nexus</name> <url>http://maven.oschina.net/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://maven.oschina.net/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> </settings>
測試一下:在eclipse中創建一個maven工程,然后在eclipse的console窗口中,選擇maven console。就可以看到加載的包的來源了。
右下角的倒三角箭頭鼠標懸浮上去后,有很多console列表,選擇maven console即,點擊即可切換到maven窗口,可看到有關下載源的信息,如下圖:
-------------------------------------------補充更新------------------------------------------------------------------------------
settings.xml文件中,在標簽<profile>必須包含在<profiles>中,否則在使用命令行執行mvn時,會出現一些錯誤:
Error reading settings.xml: Unrecognised tag: 'profile' (position: START_TAG seen ...</mirrors>\n\n\t<profile>... @22:11)
Line: 22
Column: 11
joyven@joyven-ThinkPad-E450:/mnt/workspace/spring-mvc$ mvn archetype:generate DgroupId=joyven -DartifactId=spring-mvc -DarchetypeArtifactId=maven-archetype-webapp
修改之后則沒有了。
補充一點:
用maven創建項目:
mvn archetype:generate DgroupId=joyven -DartifactId=spring-mvc -DarchetypeArtifactId=maven-archetype-webapp
說明:maven主要依靠坐標來區分項目包。
groupId
artifactId
archetypeArtifactId
version
這四個值體現了maven包的唯一性。