Eclipse工程中配置Maven国内镜像仓库

从官网上下载jar文件非常慢,可以通过修改pom.xml来设置国内的镜像仓库,提高下载速度。

pom.xml增加下列配置项:

	<repositories>
		<repository>
			<id>repo-mirror</id>
			<name> Maven China Mirror</name>
			<url>http://maven.net.cn/content/groups/public/</url>
			<releases>
				<enabled>true</enabled>
			</releases>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
		</repository>
	</repositories>
	
	<pluginRepositories>
		<pluginRepository>
			<id>plugin-repo-mirror</id>
			<name> Maven China Mirror</name>
			<url>http://maven.net.cn/content/groups/public/</url>
			<releases>
				<enabled>true</enabled>
			</releases>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
		</pluginRepository>
	</pluginRepositories>

一劳永逸的做法是修改settings.xml配置文件,对所有工程有效:

  <!-- mirrors
   | This is a list of mirrors to be used in downloading artifacts from remote repositories.
   | 
   | It works like this: a POM may declare a repository to use in resolving certain artifacts.
   | However, this repository may have problems with heavy traffic at times, so people have mirrored
   | it to several places.
   |
   | That repository definition will have a unique id, so we can create a mirror reference for that
   | repository, to be used as an alternate download site. The mirror site will be the preferred 
   | server for that repository.
   |-->
  <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>maven.net.cn</id>
      <name>one of the central mirrors in china</name>
      <url>http://maven.oschina.net/content/groups/public/</url>
      <mirrorOf>central</mirrorOf>
    </mirror>
  </mirrors>


2016/11/25 最近国内的镜像服务器不可用,更新几个可用的Maven镜像服务器:

	<mirror>    
		<id>repo1</id>    
		<mirrorOf>central</mirrorOf>    
		<name>Human Readable Name for this Mirror.</name>    
		<url>http://repo1.maven.org/maven2/</url>    
	</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>uk</id>    
		<mirrorOf>central</mirrorOf>    
		<name>Human Readable Name for this Mirror.</name>    
		<url>http://uk.maven.org/maven2/</url>    
	</mirror> 


如果有可用的代理服务器,也可以在settings.xml里设置代理服务器:

  <!-- proxies
   | This is a list of proxies which can be used on this machine to connect to the network.
   | Unless otherwise specified (by system property or command-line switch), the first proxy
   | specification in this list marked as active will be used.
   |-->
  <proxies>
    <!-- proxy
     | Specification for one proxy, to be used in connecting to the network.
     |
    <proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <username>proxyuser</username>
      <password>proxypass</password>
      <host>proxy.host.net</host>
      <port>80</port>
      <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>
    -->
  </proxies>

参考资料:

1. Maven仓库管理之Nexus:http://my.oschina.net/aiguozhe/blog/101537

2. Maven respository: http://blog.youkuaiyun.com/joewolf/article/details/4876604

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值