解决使用eclipse创建maven web项目时报Could not resolve archetype的问题

前两天重装了系统,今天想写一个项目的时候出现了点问题。

在使用eclipse创建maven web项目时,点Finish后报了Could not resolve archetype的问题。

Could not resolve archetype org.apache.maven.archetypes:maven-archetype-webapp:1.0 from any of the configured repositories.
Could not resolve artifact org.apache.maven.archetypes:maven-archetype-webapp:pom:1.0
Failure to transfer org.apache.maven.archetypes:maven-archetype-webapp:pom:1.0 from https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact org.apache.maven.archetypes:maven-archetype-webapp:pom:1.0 from/to central (https://repo.maven.apache.org/maven2): repo.maven.apache.org
Failure to transfer org.apache.maven.archetypes:maven-archetype-webapp:pom:1.0 from https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact org.apache.maven.archetypes:maven-archetype-webapp:pom:1.0 from/to central (https://repo.maven.apache.org/maven2): repo.maven.apache.org

网上比较流行的解决方法有两种:

1.在Eclipse Maven配置中添加新的Catalog配置

2.在本地库中装载maven-archetype-quickstart

我先试了试第一个方法,配置后没有任何效果。再用第二个方法,配置完后试着创建maven-archetype-quickstart 类型的项目创建成功,但maven web项目依然报错。

既然都没有效果,我决定自己分析下报错内容再去解决问题。

先看报错的第一句话,

Could not resolve archetype org.apache.maven.archetypes:maven-archetype-webapp:1.0 from any of the configured repositories.

这段话的大致意思是:无法从任何已经配置的库里面解析 org.apache.maven.archetypes:maven-archetype-webapp:1.0。

所以我在尝试第二种办法时行不通的原因是因为缺少webapp 这个包,而我们从第二步中安装的只是maven-archetype-quickstart这个项目包。

再看第二段第一句话:从https://repo.maven.apache.org/maven2下载org.apache.maven.archetypes:maven-archetype-webapp:pom:1.0失败。

从这里就能知道了目前的问题是org.apache.maven.archetypes:maven-archetype-webapp:pom:1.0这个包在创建maven web项目时maven找不到,或者是找到了但没有办法解析。当找不到或者无法解析时,maven又不能从远程仓库下载下来。

所以我们可以有两种解决方法:

  1. 第一种是在本地库中装载maven-archetype-webapp ,下载 maven-archetype-webapp 包然后放到Maven 仓库对应的路径下。
  2. 第二种方法是你先删掉现在本地仓库中的maven-archetype-webapp 这个包然后创建项目,让maven自动从远程仓库获取该包。

注:maven-archetype-webapp 包的路径是(%你的默认本地仓库%\repository\org\apache\maven\archetypes\maven-archetype-webapp\1.0)

方法2的思路来自maven下载jar包到本地仓库时会产生.lastupdate文件而导致该包无法使用。

 


 

补充一个不错的方法:

先在CMD中执行mvn help:system命令行,执行后会下载很多东西,等待下载结束。

命令行执行:mvn archetype:generate -DgroupId={project-packaging} -DartifactId={project-name} -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false?

此时会下载所需要的项目jar包,等待下载完毕就可以创建项目了。

 

posted @   六层楼  阅读(47523)  评论(6编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
点击右上角即可分享
微信分享提示