maven不能下载中央库jar问题的解决

使用Maven搭建开发环境时,提示:[INFO] Scanning for projects...
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.4.1/maven-clean-plugin-2.4.1.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-clean-plugin:2.4.1: Plugin org.apache.maven.plugins:maven-clean-plugin:2.4.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-clean-plugin:jar:2.4.1

Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-install-plugin/2.3.1/maven-install-plugin-2.3.1.pom

原因是从国外http://repo1.maven.org下载库速度很慢所致,我的做法是,找到Maven安装目录里的配置文件conf,打开settings.xml文件,maven默认把jar下载到C盘:用户/用户名文件夹/.m2/repository,把jar下载到系统盘是一个很不安全的做法,所以我修改conf里的setting.xml文件,将jar存放到指定的目录,<localRepository>D:\maven\mavenJars\repository</localRepository>。这里需要注意的是,要把默认存放目录那部分注释去掉,否则这样的修改将不会生效,到时maven还会把jars下载到C盘的m2文件夹里的,不要以为注释掉就没有影响。

 其次,指定maven下载jar的来源地,在settings.xml文件中找到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>  
  <name>aliyun maven</name>  
  <url>http://maven.aliyun.com/nexus/content/groups/public/</url>  
  <mirrorOf>central</mirrorOf>          
   </mirror>  
<mirror>
      <!--This sends everything else to /public -->
      <id>nexus</id>
      <mirrorOf>*</mirrorOf> 
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
    </mirror>
    <mirror>    
      <id>ibiblio.org</id>    
      <name>ibiblio Mirror of http://repo1.maven.org/maven2/</name>    
      <url>http://mirrors.ibiblio.org/pub/mirrors/maven2</url>    
      <mirrorOf>central</mirrorOf>    
   </mirror>  

保存,再重新建maven项目就正常了

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值