背景介绍:
在使用Spring tool suite (Eclipse) 创建maven webapp项目总遇到错误。详细错误如下。
could not resolve archetype org.apache.maven.archetypes:maven-archetype-webapp:RELEASE from any of the configured repositories
Could not resolve archetype org.apache.maven.archetypes:maven-archetype-webapp:RELEASE from any of the configured repositories.
Could not resolve artifact org.apache.maven.archetypes:maven-archetype-webapp:pom:RELEASE
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 (E:\Maven\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 (E:\Maven\repository)
在控制台中使用 mvn help:system 命令,发现创建maven project时候下载都是失败的。因此很有可能是网络原因引起的。我的网络环境使用的代理。因此要给maven的配置文件 %MAVEN_HOME%/conf/settings.xml 加上代理配置:
<proxies>
<!-- proxy
| Specification for one proxy, to be used in connecting to the network.
|
-->
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<username>proxyuser</username>
<password>proxypass</password>
<host>proxy.host.net</host>
<port>80</port>
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>
</proxies>
重新构建maven项目,用 mvn help:system 命令观察,maven能够成功下载资源!