從SVN新檢出一個maven項目,配置好后,發現項目無法編譯(只有一個test包中的代碼顯示編譯報錯,其他所有包中的代碼都不編譯,也不報錯),
先注釋掉報錯的test包中的所有內容,
用Eclipse自帶的 maven執行clean命令,失敗,異常信息為:
Plugin org.apache.maven.plugins:maven-clean-plugin:2.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-clean-plugin:jar:2.5: Could not transfer artifact org.apache.maven.plugins:maven-clean-plugin:pom:2.5 from/to alimaven (http://maven.aliyun.com/nexus/content/groups/public/): Cannot access http://maven.aliyun.com/nexus/content/groups/public/ with type default using the available connector factories: BasicRepositoryConnectorFactory: Cannot access http://maven.aliyun.com/nexus/content/groups/public/ using the registered transporter factories: WagonTransporterFactory: java.util.NoSuchElementException
[ERROR] role: org.apache.maven.wagon.Wagon
參考了如下文章:
------------------轉載開始---------------
mvn clean package報錯 WagonTransporterFactory: java.util.NoSuchElementException
在eclipse中執行clean package指令報錯,錯誤信息如下:
-
[
-
[
-
[
-
[
-
[
-
[
-
[
-
[
-
[
-
[
-
[
-
[
-
[ERROR] role: org.apache.maven.wagon.Wagon
-
[ERROR] roleHint: http
-
[ERROR] -> [Help 1]
-
[ERROR]
-
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
-
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
-
[ERROR]
-
[ERROR] For more information about the errors and possible solutions, please read the following articles:
-
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException
-
網上有很多解決辦法,分別如下:
- 由於maven默認的下載服務器在國外,網絡不好下載不好jar包,讓修改maven_home/conf目錄下的setting文件,增加阿里的下載鏡像地址,然后重新下載插件;
- 刪除插件在本地倉庫中的目錄,重新下載,不停的嘗試,直到可行為止
- 等等等。。。。。。
小編在嘗試上面的兩種方式之后,最終的解決辦法:
在cmd窗口進入到項目目錄下,執行指令mvn clean package,然后就BUILD SUCCESS,試100次成功100次,回頭再到eclipse中執行,也BUILD SUCCESS了
個種原因我就不是很清楚,只是不再相信eclipse的這些插件了。還是老老實實在cmd窗口敲命令
------------------轉載結束--------------
想到可能是Eclipse自帶的maven插件不太好用,於是,用本地安裝的 maven,在項目目錄下,打開黑窗口,執行 clean ,成功了,沒有報錯,進而想到,可以在Eclipse中使用本地的maven,方法如下:
本地安裝的 maven目錄:
也就是填到 bin的上級目錄即可。
再次用Eclipse 執行 clean ,通過了,沒有報錯。
-------------------------------------------------
但是項目中的其他包中的代碼還是不編譯,而且在Eclipse中的執行 maven 的compile 指令
方法為,在項目上右鍵,run as ——maven build ...
雖然執行成功,但是 日志顯示 沒有可編譯的文件。
。。。
各種百度、測試,最終把目標轉移到項目下的 .classpath 文件
此文件需要在Eclipse的 Navigator 視圖中才能看到,或者直接到項目目錄中去找:
經過和一個本地正常的maven 項目的 .classpath文件比較
正常項目的 .classpath 文件:
<?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" output="target/classes" path="src/main/java"> <attributes> <attribute name="optional" value="true"/> <attribute name="maven.pomderived" value="true"/> </attributes> </classpathentry> <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"> <attributes> <attribute name="maven.pomderived" value="true"/> </attributes> </classpathentry> <classpathentry kind="src" output="target/test-classes" path="src/test/java"> <attributes> <attribute name="optional" value="true"/> <attribute name="maven.pomderived" value="true"/> <attribute name="test" value="true"/> </attributes> </classpathentry> <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"> <attributes> <attribute name="maven.pomderived" value="true"/> <attribute name="test" value="true"/> </attributes> </classpathentry> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"> <attributes> <attribute name="maven.pomderived" value="true"/> </attributes> </classpathentry> <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> <attributes> <attribute name="maven.pomderived" value="true"/> <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/> </attributes> </classpathentry> <classpathentry kind="output" path="target/classes"/> </classpath>
異常項目的 文件:
<?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry excluding="**/test/" kind="src" output="target/classes" path="src/main/java"> <attributes> <attribute name="optional" value="true"/> <attribute name="maven.pomderived" value="true"/> </attributes> </classpathentry> <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"> <attributes> <attribute name="maven.pomderived" value="true"/> </attributes> </classpathentry> <classpathentry exported="true" kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> <attributes> <attribute name="maven.pomderived" value="true"/> <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/> </attributes> </classpathentry> <classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"> <attributes> <attribute name="maven.pomderived" value="true"/> </attributes> </classpathentry> <classpathentry exported="true" kind="lib" path="G:/ty/oracle/jdbc_qudong/ojdbc14-10.2.0.4.0.jar"> <attributes> <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/> </attributes> </classpathentry> <classpathentry kind="src" output="target/test-classes" path="src/test/java"> <attributes> <attribute name="test" value="true"/> <attribute name="optional" value="true"/> <attribute name="maven.pomderived" value="true"/> </attributes> </classpathentry> <classpathentry kind="output" path="target/classes"/> </classpath>
發現,其在 主要源文件目錄 src/main/java的相關配置中,前面多了一個 excluding="**/test/"
我靠,這個不正是項目中唯一被會被編譯的 包的路徑嘛,
想到這,直接把 excluding="**/test/" 這個 刪除,保存,然后重啟 Eclipse,所有包都編譯了,故障排除。
---------------
啟發:
剛從svn檢出的項目,如果經過各種排查后還是有問題,尤其是 不編譯 類 問題,可以查看一下項目下的 .classpath 文件,這個文件第一次檢出項目時,會從 svn 上更新下來,然后隨着本地的操作會發生變化。
如果svn上被提交的源 .classpath 文件就有問題,或者由於檢出后本地的某些操作,也可能導致 這個文件出現異常,最終結果就是導致項目的構建發生各種問題。
排查其是否有問題的方法
1、可以在本地新建一個好用的maven項目,然后用其自動生成的 .classpath 文件,和故障項目的 文件比對。
2、可以直接使用上面文章中的例子
3、可以和同事好用的項目中的文件比對。