栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Could not transfer artifact com.mchange:c3p0:pom:0.9.5.5 from/to central maven项目依赖注入失败三种解决方案

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Could not transfer artifact com.mchange:c3p0:pom:0.9.5.5 from/to central maven项目依赖注入失败三种解决方案

目录

报错情况:Could not transfer artifact com.mchange:c3p0:pom:0.9.5.5 from/to central

解决方案

1.在maven设置文件settings.xml中添加镜像,使用阿里云仓库

2.在自己创建的maven项目的pom.xml中覆盖super pom的仓库内容

3.在C:Users{你的用户名}.m2路径删除.m2文件夹,让maven全部重新导入(有奇效)


报错情况:Could not transfer artifact com.mchange:c3p0:pom:0.9.5.5 from/to central

创建maven项目后,前期在pom.xml注入c3p0依赖时不管如何更换version或者groupId一直显示Could not transfer artifact com.mchange:c3p0:pom:0.9.5.5 from/to central(https://repo.maven.apache.org/maven2)的问题,依赖始终注入失败。

       
            com.mchange
            c3p0
            0.9.5.2
        

解决方案

1.在maven设置文件settings.xml中添加镜像,使用阿里云仓库

在C:Users{你的用户名}.m2 下找到settings.xml,如果找不到或不确定具体路径,可以在IDEA的文件-设置中找到“用户设置文件”,就能知道其位置。

 然后在settings.xml里添加如下代码:


        	  
      
           alimaven
           central
           aliyun maven
           https://maven.aliyun.com/nexus/content/repositories/central/          
       

       
       
            repo1
            central
            Human Readable Name for this Mirror.
            http://repo1.maven.org/maven2/
       

       
       
             repo2
             central
             Human Readable Name for this Mirror.
             http://repo2.maven.org/maven2/
       

2.在自己创建的maven项目的pom.xml中覆盖super pom的仓库内容

参考https://stackoverflow.com/questions/12789488/how-do-you-stop-maven-from-trying-to-access-http-repo-maven-apache-org

可知,所有pom文件都会继承maven super POM的内容,其中关于super POM中关于仓库有如下配置


    
        central
        Central Repository
        http://repo.maven.apache.org/maven2
        default
        
            false
        
    

所以才会导致当依赖注入时会先去(https://repo.maven.apache.org/maven2)里找,而由于国内网络限制的原因,很多资源无法访问下载。

这时,需要在我们自己创建的该maven项目的pom.xml里添加如下代码,对super POM的仓库配置进行覆盖


      
            central
            http://host:port/content/groups/public
      



      
             central
             http://host:port/content/groups/public
       

3.在C:Users{你的用户名}.m2路径删除.m2文件夹,让maven全部重新导入(有奇效)

如果在尝试过方法1与方法2后,在刷新时依赖仍无法注入,比如此时显示“无法访问 Maven 3.8.1 http 仓库”的报错,建议删除C:User{你的用户名} 下的.m2文件,清除缓存,让maven项目全部重新导入一次,重新建立.m2文件夹。可解决报错。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/956484.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号