今天學習maven,在控制檯下新建maven項目沒有問題,可是在STS(eclipse)下建立maven項目總是報錯,鬱悶死了:html
----------------------------------------------------web
錯誤信息: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 (F:\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 (F:\maven\repository)apache
----------------------------------------------------app
遇到問題,就是baidu/google查找解決方法,惋惜網上不少人提到的方法試了都不行,鬱悶了好幾個小時,最後找到問題緣由以下:框架
以上報錯的緣由是:在settings.xml 文件中 mirrors出了問題。默認maven3.1.0安裝目錄下的conf目錄下的setting.xml配置文件中的mirrors配置是這樣的:eclipse
<mirrors> webapp
<!-- mirror maven
| Specifies a repository mirror site to use instead of a given repository. The repository that 學習
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used this
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
|
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
-->
</mirrors>
<mirrors> <!-- mirror | Specifies a repository mirror site to use instead of a given repository. The repository that | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used | for inheritance and direct lookup purposes, and must be unique across the set of mirrors. | <mirror> <id>mirrorId</id> <mirrorOf>repositoryId</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://my.repository.com/repo/path</url> </mirror> --> </mirrors>
我也不是很清楚爲何就是不行(猜想是maven默認的internet倉庫裏的文件不全,因此就添加了你們用得最多的maven的internet倉庫之一:lbiblio,基本全部的開源的框架的jar文件都有提供),而後在setting.xml配置文件上面我添加了一個新的mirror,添加後以下:
<mirrors>
<!-- mirror
| Specifies a repository mirror site to use instead of a given repository. The repository that
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
|
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
-->
<!--如下是新增長上去的-->
<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>
<mirrors> <!-- mirror | Specifies a repository mirror site to use instead of a given repository. The repository that | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used | for inheritance and direct lookup purposes, and must be unique across the set of mirrors. | <mirror> <id>mirrorId</id> <mirrorOf>repositoryId</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://my.repository.com/repo/path</url> </mirror> --> <!--如下是新增長上去的--> <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>
就只是修改了setting.xml配置文件上的這個地方,而後在控制檯下我從新輸入:
mvn help:system
回車,就能夠看到從新下載了好多的jar包文件。
等下載完成後,再在eclipse新建maven項目就正常了。