maven找不到jar包,maven下载不了jar包,maven只能下载带有.lastUpdated结尾的文件,.pom.lastUpdated结尾文件,maven不能从中央仓库拉取jar包,解决方法


问题现象:

1.用eclipse配置maven后打开maven工程,提示jar包missing错误,就是本地仓库中没有找到那些jar包,从网上的中央仓库下载也失败了,所以会报找不到jar包的错误。

2.最近刚开始学习maven工具,下载解压完毕,环境变量配置完毕,运行如下命令尝试快速构建一个maven项目:
1.建立D:/test文件夹。
2.在命令行中进入D:/test文件夹
3.运行命令 mvn archetype:generate

结果就有问题:

[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
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-install-plugin:2.3.1: Plugin org.apache.maven.plugins:maven-install-plugin:2.3.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-install-plugin:jar:2.3.1

这种hello world级别的操作出错,就怀疑是网络问题,于是让其他同事帮我尝试访问http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.4.1/maven-clean-plugin-2.4.1.pom地址,发现完全没问题,感觉异常郁闷。
后来网上查了一下,发现是因为maven无法访问maven.org网站。


解决此问题的办法:

设置镜像:在maven的配置文件中设置能够访问的中央仓库的mirrors。

配置方式如下:
1、打开maven配置文件(maven安装目录下的conf目录下的settings.xml文件)
2、搜索mirrors关键字,如果注释说明的下方没有 <mirrors>节点,则建立mirrors节点,带mirrors节点的所有配置如下(复制下面的内容,粘贴到配置文件中即可):

<mirror>
        <id>nexus-aliyun</id>
        <name>Nexus aliyun</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
        <mirrorOf>central</mirrorOf>
</mirror>

配置镜像后,删除本地仓库中的所有文件,再次打开工程,看到jar包下载成功,问题完美解决,一切都正常了。

猜你喜欢

转载自blog.csdn.net/qq_39559604/article/details/80870428