Maven:Could not resolve archetype

在创建maven-archetype-webapp项目时,总是抛出以下异常:

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 http://maven.oschina.net/content/groups/public/ was cached in the local repository, resolution will not be reattempted until the update interval of maven-net-cn has elapsed or updates are forced. Original error: Could not transfer artifact org.apache.maven.archetypes:maven-archetype-webapp:pom:1.0 from/to maven-net-cn (http://maven.oschina.net/content/groups/public/): Connection refused: connect
Failure to transfer org.apache.maven.archetypes:maven-archetype-webapp:pom:1.0 from http://maven.oschina.net/content/groups/public/ was cached in the local repository, resolution will not be reattempted until the update interval of maven-net-cn has elapsed or updates are forced. Original error: Could not transfer artifact org.apache.maven.archetypes:maven-archetype-webapp:pom:1.0 from/to maven-net-cn (http://maven.oschina.net/content/groups/public/): Connection refused: connect


此问题在网上有很多文章说已经解决,但试试,一开始都不行,经常不但的尝试,分析,终于解决。现将解决过程描述如下:

首先从错误信息说起:

错误信息是说,不能从远端下载maven-archetype-webapp:pom:1.0。

可为什么要下载这个呢。根据Maven官方对archetype的定义如下:

In short, Archetype is a Maven project templating toolkit. An archetype is defined as an original pattern or model from which all other things of the same kind are made.

可以知道,archetype是Maven各项目的配置模板。在创建项目时,会根据创建的项目类型,下载相应的模板配置信息。


archetype文件为各种项目类型,也就是下图所看到的类型。以及各种类型的项目模板的远程地址。创建项目时,会从配置的地址下载配置数据。


如果没有相应的项目类型,到网上下载,再配置到Maven中。我下载的文件是地址为:

http://maven.oschina.net/content/groups/public/archetype-catalog.xml

此文件中有相当多的项目类型,我平时也用两种,所以我其它的删除了变成了以下的内容:

<?xml version="1.0" encoding="UTF-8"?>
<archetype-catalog xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-catalog/1.0.0 http://maven.apache.org/xsd/archetype-catalog-1.0.0.xsd"
    xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-catalog/1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <archetypes>
    
	<archetype>
      <groupId>org.apache.maven.archetypes</groupId>
      <artifactId>maven-archetype-webapp</artifactId>
      <version>1.0-alpha-4</version>
      <repository>http://maven.oschina.net/content/groups/public</repository>
    </archetype>
	
	<archetype>
      <groupId>org.apache.maven.archetypes</groupId>
      <artifactId>maven-archetype-quickstart</artifactId>
      <version>1.0-alpha-4</version>
      <repository>http://maven.oschina.net/content/groups/public</repository>
    </archetype>
	
  </archetypes>
</archetype-catalog>

在Eclipse中 Window -> Preferences -> Maven -> ArcheTypes : Add Local Catalog  在弹出的对话框中选择下载的文件即可。建议重启一下Eclipse。

在创建项目时,选择相应的项目,会看到下载配置信息的过程。


我用网上其它方法不能解决的原因:

1. 有的提供的archetype文件下载地址,下载的文件中没有项目的远程地址信息,当然也就不可能下载项目配置模板数据。

2. 就是我所使用的网络较差,连接不到远程服务器,导致失败(因为我在下载archetype文件时都用了好长时间,有时还下载不了)




猜你喜欢

转载自blog.csdn.net/lijing_lj928/article/details/50598610