天天看點

使用maven 容易遇到的問題

項目中使用了maven,而且搭建了nexus 私服。

經常會遇到如下問題:

(一)

使用maven建構的項目下面都有一個pom.xml檔案,裡面設定了該項目的依賴的jar包。第一次因為沒有聯網或者nexus服務未啟動,導緻下載下傳jar失敗,以後依然下載下傳失敗。後來終于找到了原因:

因為第一次下載下傳失敗時,會在c:\users\huangwei\.m2\repository 中生成對應jar包的lastupdated檔案,如xwork-core-2.1.6.jar.lastupdated。因為有這個lastupdated檔案,是以以後都不會真正下載下傳xwork-core-2.1.6.jar了。

解決方法:(1)在執行mvn compile 之前把lastupdated 檔案删除;

(2)mvn compile -u

(二)使用maven 編譯(mvn compile)時,報錯:maven source 1.3 中不支援泛型

解決方法:在項目的pom.xml中添加:

使用maven 容易遇到的問題

<build>  

    <plugins>  

      <plugin>  

        <groupid>org.apache.maven.plugins</groupid>  

        <artifactid>maven-compiler-plugin</artifactid>  

        <configuration>  

          <source>1.6</source>  

          <target>1.6</target>  

        </configuration>  

      </plugin>  

    </plugins>  

    </build>  

使用maven 容易遇到的問題

解決方法:

執行deploy時指定jre的參數

-xms128m -xmx512m

使用maven 容易遇到的問題

(四)使用nexus 時,eclipse中 maven repositories 視圖中的global repositories下的nexus 無法展開

使用maven 容易遇到的問題

 解決方法:

對nexus 中public repositories 先執行“rebuild metadata”,再執行“update index”:

使用maven 容易遇到的問題

(五)使用eclipse 執行deploy部署項目時報錯,報錯資訊如下:

使用maven 容易遇到的問題

failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project demomanagement: failed to deploy artifacts: could not find artifact com.kunlunsoft.jn:demomanagement:war:1.1.0-release in tdr_vks_management_release (http://192.168.2.150:8088/nexus/content/repositories/kunlun_management_release/) -> [help 1]  

 項目名為demomanagement

剛開始以為是pom。xml中finalname 引起的。結果發現nexus 壓根兒沒有叫“kunlun_management_release”的倉庫。

根本原因:pom.xml中snapshotrepository指定的倉庫不存在。

繼續閱讀