前些时候我学习Maven,我遇到了以下两个错误(该死的这两个错误,让我浪费了四天时间):
1、Could not resolve archetype org.apache.maven.archetypes:maven-archetype-webapp:RELEASE from any of the configured repositories.
Could not resolve artifact
Failed to resolve version for org.apache.maven.archetypes:maven-archetype-webapp:pom:RELEASE: Could not find metadata org.apache.maven.archetypes:maven-archetype-webapp/maven-metadata.xml in local (D:\m2\repository)
Failed to resolve version for org.apache.maven.archetypes:maven-archetype-webapp:pom:RELEASE: Could not find metadata org.apache.maven.archetypes:maven-archetype-webapp/maven-metadata.xml in local (D:\m2\repository)
(这个错误是在新建项目的时候报的)
2、Could not calculate build plan: Could not find artifact org.apache.maven.plugins:maven-resources-plugin:pom:2.4.3 in jboss-public-repository-group (http://repository.jboss.org/nexus/content/groups/public)AsamMilkTea5未知Maven Problem(这个错误是在构建的时候报出的)
以上报错的原因是:在settings.xml 文件中 mirrors出了问题(Maven 2 Mirror的陷阱)。以前我是多个mirror 后来改为用一个mirror
<mirrors>
<mirror>
<id>ibiblio.org</id>
<name>ibiblio Mirror of http://repo1.maven.org/maven2/</name>
<url>http://mirrors.ibiblio.org/pub/mirrors/maven2</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
其它不要,就只要这个,就解决以上问题。
感谢welkin.hu,看了他的"Maven 2 Mirror的陷阱"这篇博文,是我解决这个问题的启发点。
Maven 2 Mirror的陷阱 (http://welkinhu.blog.51cto.com/447606/107230)
Maven 2的安装和使用虽然不是一点即用,但也不是很复杂。然而,这两天我新装Maven,刚刚过了mvn -version,尝试create maven project就出问题了。问题详情如下。
D:\mavenSample>mvn archetype:create -DgroupId=com.mycompany.app -DartifactId=my-app
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'archetype'.
[INFO] org.apache.maven.plugins: checking for updates from central
[INFO] org.codehaus.mojo: checking for updates from central
[INFO] artifact org.apache.maven.plugins:maven-archetype-plugin: checking for updates from central
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] The plugin 'org.apache.maven.plugins:maven-archetype-plugin' does not exist or no valid version could be found
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3 seconds
[INFO] Finished at: Wed Mar 19 14:26:49 CST 2008
[INFO] Final Memory: 1M/2M
[INFO] ------------------------------------------------------------------------
开始以为是internet 代理设置有问题。网上也有帖子这么说。可是换到ADSL后,不用代理了,问题仍然存在。
几经周折后发现,原因在于我画蛇添足多加了几个镜像,其中有的镜像没有同步更新maven库。经过测试,如下maven 镜像工作正常:
<mirror>
<id>ibiblio.org</id>
<mirrorOf>central</mirrorOf>
<!-- United States, North Carolina -->
</mirror>
<mirror>
<id>redv.com</id>
<mirrorOf>central</mirrorOf>
<!-- Shanghai, China , Very fast-->
</mirror>
<mirror>
<id>dotsrc.org</id>
<mirrorOf>central</mirrorOf>
<!-- Denmark -->
</mirror>
<mirror>
<id>sunsite.dk</id>
<mirrorOf>central</mirrorOf>
<!-- Denmark -->
</mirror>
<mirror>
<id>skynet.be</id>
<mirrorOf>central</mirrorOf>
<!-- Belgium -->
</mirror>
<mirror>
<id>cica.es</id>
<mirrorOf>central</mirrorOf>
<!-- Spain, Sevilla -->
</mirror>
<!-- these just point to ibiblio.org -->
<mirror>
<id>ibiblio.net</id>
<mirrorOf>central</mirrorOf>
<!-- United States, North Carolina Fast-->
</mirror>
而下面的Maven镜像都有问题。
<mirror>
<id>planetmirror</id>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>lsu.edu</id>
<mirrorOf>central</mirrorOf>
<!-- United States, Louisiana -->
</mirror>
<mirror>
<id>sateh.com</id>
<mirrorOf>central</mirrorOf>
<!-- The Netherlands, Amsterdam -->
</mirror>
<mirror>
<id>ggi-project.org</id>
<mirrorOf>central</mirrorOf>
<!-- The Netherlands, Amsterdam -->
</mirror>