天天看點

Maven項目起不來,報[ERROR] For more information about the errors and possible solutions, please read the fo5、引入自己的jar包出現問題。

[INFO] BUILD FAILURE

[ERROR] Failed to execute

[ERROR] For more information about the errors and possible solutions, please read the following articles:

1、問題情形

項目代碼是從SVN上剛下載下傳的。

同僚在啟動項目時,程式卡在下圖這個地方不動了(請忽略圖檔上的時間):

Maven項目起不來,報[ERROR] For more information about the errors and possible solutions, please read the fo5、引入自己的jar包出現問題。

可以看出,項目已經在啟動了,但是中途遇到了不知名的情況,卡着不動了,等了好長時間也不往下走。

但是我們其他同僚都能成功啟動,同樣的代碼,别人起得來,就他起不來,肯定有原因。

2、查找原因

同僚用run configurations啟動,指令是clean tomcat7:run,模式是Offline

Maven項目起不來,報[ERROR] For more information about the errors and possible solutions, please read the fo5、引入自己的jar包出現問題。

對于Offline(離線模式),我的了解就是脫機,不受限制,即不聯網進行jar包校驗,隻要有這個jar包就行。不使用Offline就意味着需要聯網進行一系列的校驗。就好比開着,Offline就是隻要有車我就開,就算是開半路車要爆炸那我也開;而聯網的時候呢,就是我先把這輛車檢查一下,一旦發現問題,那我就不開了。

我把Offline(離線模式)取消勾選,如下圖: 

Maven項目起不來,報[ERROR] For more information about the errors and possible solutions, please read the fo5、引入自己的jar包出現問題。

奇迹出現了,系統列印了錯誤(請忽略圖檔上的時間):

Maven項目起不來,報[ERROR] For more information about the errors and possible solutions, please read the fo5、引入自己的jar包出現問題。

三行關鍵資訊,可以推斷是Maven引入依賴是出現錯誤:

[INFO] BUILD FAILURE

[ERROR] Failed to execute

[ERROR] For more information about the errors and possible solutions, please read the following articles:

很明顯嘛,那行藍色的提示資訊就明确表示了錯誤原因是:解決依賴關系出現錯誤。

Maven項目起不來,報[ERROR] For more information about the errors and possible solutions, please read the fo5、引入自己的jar包出現問題。

當然,有時候提示的不是這些,而是其他的。但是根據紅框圈中的那三行關鍵資訊,基本可以鎖定是這類問題。

3、解決問題

問題原因已經清楚了,那怎麼解決呢?

來看[INFO] BUILD FAILURE這行上面的那些資訊,

Maven項目起不來,報[ERROR] For more information about the errors and possible solutions, please read the fo5、引入自己的jar包出現問題。

Maven需要下載下傳一些檔案,但是試過所有下載下傳連接配接後也沒能下載下傳成功(通常是需要翻牆,也可能是連接配接錯誤),那麼我們來手動下載下傳。

我沒這麼幹,我直接從其他能正常啟動這個項目的同僚那邊拷了整個的org.eclipse包,替換掉這位同僚原來的包。然後項目成功啟動。

手動下載下傳的話,我一般都是去https://repo.maven.apache.org/maven2/下載下傳。

下載下傳的時候最好是将自己本地的删除掉,然後将中央倉庫裡這個包下的jar、pom、xml什麼的全下下來,然後複制到本地倉庫。

4、還有之前遇到的一些類似的問題

日志顯示三行關鍵的地方:

[INFO] BUILD FAILURE

[ERROR] Failed to execute

[ERROR] For more information about the errors and possible solutions, please read the following articles:

Maven項目起不來,報[ERROR] For more information about the errors and possible solutions, please read the fo5、引入自己的jar包出現問題。

來看[INFO] BUILD FAILURE這一行上邊的,

Maven項目起不來,報[ERROR] For more information about the errors and possible solutions, please read the fo5、引入自己的jar包出現問題。

可以猜測下載下傳這個pom檔案時出了問題,我不研究到底出了什麼問題(有時候是因為需要翻牆),直接從中央倉庫重新下載下傳:

https://repo.maven.apache.org/maven2/org/apache/httpcomponents/project/5/

我把目錄下的檔案全下載下傳下來,然後替換到本地倉庫:

Maven項目起不來,報[ERROR] For more information about the errors and possible solutions, please read the fo5、引入自己的jar包出現問題。

重新啟動項目,OK,啟動成功

5、引入自己的jar包出現問題。

工作中,經常會遇到一些自己公司封裝的jar包,由于是自己封裝的,是以大多都是在本地倉庫,各同僚間互相拷貝。

但是,在Maven項目中,是通過pom檔案找到對應jar包的。是以,如果本地沒有pom檔案,那麼以線上模式啟動maven的話,一定會報錯。

解決辦法就是:手動寫一個pom檔案

比如我們公司自己封裝了一個關于json的jar包,名為:json-1.0.jar,在maven倉庫位置:本地maven倉庫根路徑/org/json/json/1.0/ json-1.0.jar

需在jar包同路徑下寫下同名的pom檔案:json-1.0.pom:

Maven項目起不來,報[ERROR] For more information about the errors and possible solutions, please read the fo5、引入自己的jar包出現問題。

 pom檔案内容如下:

Maven項目起不來,報[ERROR] For more information about the errors and possible solutions, please read the fo5、引入自己的jar包出現問題。

也可以使用mvn指令自動生成pom檔案:

mvn install:install-file -DgroupId=org.json -DartifactId=json -Dversion=1.0 -Dpackaging=jar -Dfile=D:/json-1.0.jar
           
Maven項目起不來,報[ERROR] For more information about the errors and possible solutions, please read the fo5、引入自己的jar包出現問題。

在指令行執行以下就行