解决使用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

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

然后我就想到了分析下报错内容再去解决问题。

看看报错的第一句话,大致意思是:无法从任何已经配置的库里面解析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 
  2. 删除掉目前本地仓库中的maven-archetype-webapp这个包然后创建项目,让maven自动从远程仓库获取该包。

注:该包的路径是(%你的默认本地仓库%\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包,等待下载完毕就可以创建项目了。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值