天天看點

maven坑-Failure to transfer org.apache.maven:maven

參考網址:http://www.mkyong.com/maven/how-to-convert-maven-java-project-to-support-eclipse-ide/

     https://blog.csdn.net/gsycwh/article/details/52792633

問題描述:

在建立Maven項目時,經常會在pom.xml的第一行處報錯,提示資訊如下:

Failure to transfer org.apache.maven:maven-surefire-plugin:jar:2.5 from http:// repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact org.apache.maven:maven- archiver:jar:2.5 from/to central (http://repo.maven.apache.org/maven2): The operation was cancelled.

問題分析:

  maven的plugin并未下載下傳到本地

解決辦法1(優先):

  1.Navigate to your Java project folder, where 

pom.xml

 file is placed.

    mvn eclipse:eclipse

     【 如果有錯誤,會顯示錯誤的原因。】

  2.根據錯誤原因,你可以到本地庫中搜尋“.lastUpdated”結尾的檔案,找到一份 maven-surefire-plugin-2.7.1.pom.lastUpdated的檔案,将其删除。如未自行設定,本地倉庫為C:\Users\admin\.m2\repository。

  3. mvn eclipse:eclipse 

    【成功】

解決辦法2:

  1. 你可以到本地庫中搜尋“.lastUpdated”結尾的檔案,找到一份 maven-surefire-plugin-2.7.1.pom.lastUpdated的檔案,将其删除。如未自行設定,本地倉庫為C:\Users\admin\.m2\repository。

  2.回到項目中,在項目右鍵點選project -> Maven -> Update Dependencies(Update Project…)更新項目,這時候應該就沒有錯了。

注意:

  1.maven-surefire-plugin-2.7.1.pom.lastUpdated檔案不是固定的,而是要看報錯的具體資訊,如上面錯誤資訊中,主要看報錯的maven:後面緊跟的資訊

  2.方法一和方法二的差別在于 錯誤的原因更詳細、具體、準确。