1. 程式人生 > >Maven 報:Could not find artifact org.apache.maven.plugins:maven-resources-plugin:pom:2.4.3

Maven 報:Could not find artifact org.apache.maven.plugins:maven-resources-plugin:pom:2.4.3

前些時候我學習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的安裝和使用雖然不是一點即用,但也不是很複雜。然而,這兩天我新裝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映象都有問題。