创建maven项目时出现的一个问题

Could not resolve archetype

       当时刚配好maven项目的配置环境及项目运行环境,然后第二天真不巧,当我在使用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

解决方法:

       

当时我上网查询到两种方法:

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又不能从远程仓库下载下来。

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

第一种是在本地库中装载maven-archetype-webapp ,下载 maven-archetype-webapp 包然后放到Maven 仓库对应的路径下。
第二种方法是你先删掉现在本地仓库中的maven-archetype-webapp 这个包然后创建项目,让maven自动从远程仓库获取该包。
注:maven-archetype-webapp 包的路径是(%你的默认本地仓库%\repository\org\apache\maven\archetypes\maven-archetype-webapp\1.0)

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

But  

我使用的是这种方法,首先在CMD中执行mvn help:system命令行,执行后会下载很多东西,等待下载结束。 

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

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

猜你喜欢

转载自blog.csdn.net/Giraffe_it/article/details/84500632