通常我們會因為下載jar包速度緩慢而苦惱,這十分影響開發效率,以及程序員的心情,在IDE下載jar時,無法對IDE做任何動作,只能大眼對小眼。
下載jar速度慢究其原因就是因為很多資源都是國外的,我們下載一個小文件幾乎就跨越了一個太平洋那么遠,那么有什么方法可以讓下載速度變快呢?
其實方法很簡單:maven是支持鏡像的,我們可以在${maven_home}的conf目錄下的setting.xml文件中找到<mirrors></mirrors>標簽
<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> --> </mirrors>
在這個標簽中加入國內的鏡像即可
這里我推薦maven阿里雲中央倉庫
<mirrors> <mirror> <id>alimaven</id> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror> </mirrors>
<mirror> <id>alimaven</id> <mirrorOf>central</mirrorOf> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/repositories/central/</url> </mirror>
下面是一些常用的maven國內鏡像
<mirror> <id>CN</id> <name>OSChina Central</name> <url>http://maven.oschina.net/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror> <mirror> <id>repo2</id> <mirrorOf>central</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://repo2.maven.org/maven2/</url> </mirror> <mirror> <id>net-cn</id> <mirrorOf>central</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://maven.net.cn/content/groups/public/</url> </mirror> <mirror> <id>ui</id> <mirrorOf>central</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://uk.maven.org/maven2/</url> </mirror> <mirror> <id>ibiblio</id> <mirrorOf>central</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url> </mirror> <mirror> <id>jboss-public-repository-group</id> <mirrorOf>central</mirrorOf> <name>JBoss Public Repository Group</name> <url>http://repository.jboss.org/nexus/content/groups/public</url> </mirror> <mirror> <id>JBossJBPM</id> <mirrorOf>central</mirrorOf> <name>JBossJBPM Repository</name> <url>https://repository.jboss.org/nexus/content/repositories/releases/</url> </mirror> <mirror> <id>antelink</id> <mirrorOf>central</mirrorOf> <name>antelink Repository</name> <url>http://maven.antelink.com/content/repositories/central/</url> </mirror> <mirror> <id>openkoala</id> <mirrorOf>central</mirrorOf> <name>openkoala Repository</name> <url>http://nexus.openkoala.org/nexus/content/groups/Koala-release/</url> </mirror> <mirror> <id>tmatesoft</id> <mirrorOf>central</mirrorOf> <name>tmatesoft Repository</name> <url>http://maven.tmatesoft.com/content/groups/public/</url> </mirror> <mirror> <id>mavensync</id> <mirrorOf>central</mirrorOf> <name>mavensync Repository</name> <url>http://mavensync.zkoss.org/maven2/</url> </mirror>