天天看點

【轉載】Nexus添加新Repository後Maven仍找不到jar包的解決方案

maven是個好東西,除了可以像ant一樣建構外,還可以讓我們申明式的取得jar包并且處理依賴包問題。maven好雖好,但他的jar包都是要去聯網下載下傳的,如果網上沒有jar(比如oracle驅動、ibe接口等),或者不能上網(比如我們公司的内外網分離),那他就費了。 

是以,maven需要個夥伴那就是“私服”,個人隻接觸過nexus,是以就用nexus了。。。 

幾步配置以後(很簡單 網上很多教程),所有jar就都從nexus中下載下傳了,并且可以友善的添加自己jar和自己的非主流repository。。。 

但在使用一段時間後,有個問題不斷浮現,并且一直困擾我,就是當我要build一個工程的時候,報錯說缺少xxx.jar包,ok,一般情況下是不在正常的repository中,要添加其他的repository(比如:scala-tools.org),之後我去nexus中加一個proxy repository後并且配入public repository,并欣喜的啟動maven,但還是有如此錯誤 

failure to find xxx:jar:1.0 in http://localhost:8081/nexus-webapp-1.9.0/content/groups/public/ was cached in the local repository, resolution will not be reattempted until the update interval of nexus has elapsed or updates are forced 

但問題我已經配好了啊!最後關鍵就是錯誤中這段was cached in the local repository, resolution will not be reattempted until the update interval of nexus has elapsed or updates are forced 

之後 去自己的.m2 檔案夾下把 xxx.lastupdated檔案全部删掉,重新運作maven,ok!或者在用maven時加 -u參數,就可以忽略xxx.lastupdated.. 

有人說這樣也可以: 

就是去nexus裡去先"update index"再"expire cache"...但我試了貌似沒有效果 

希望對大家在遇到相同問題時有幫助...