zoukankan      html  css  js  c++  java
  • 解决使用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 包的路径是(%你的默认本地仓库% epositoryorgapachemavenarchetypesmaven-archetype-webapp1.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包,等待下载完毕就可以创建项目了。

  • 相关阅读:
    (转)五大常用算法之二:动态规划算法
    (转)五大常用算法之一:分治算法
    dict
    usaco2
    usaco3
    usaco4
    usaco1
    并查集
    洛谷P1428小鱼比可爱
    洛谷P1967货车运输
  • 原文地址:https://www.cnblogs.com/rever/p/7076596.html
Copyright © 2011-2022 走看看