从SVN新检出一个maven项目,配置好后,发现项目没法编译(只有一个test包中的代码显示编译报错,其余全部包中的代码都不编译,也不报错),java
先注释掉报错的test包中的全部内容,apache
用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网络
参考了以下文章:oracle
------------------转载开始---------------eclipse
mvn clean package报错 WagonTransporterFactory: java.util.NoSuchElementException
在eclipse中执行clean package指令报错,错误信息以下:maven
-
[ INFO] Scanning for projects...
-
[ INFO]
-
[ INFO] --------------------------< com.demo:ws-demo >--------------------------
-
[ INFO] Building ws-demo 0.0.1-SNAPSHOT
-
[ INFO] -------------------------------[ bundle ]-------------------------------
-
[ INFO] ------------------------------------------------------------------------
-
[ INFO] BUILD FAILURE
-
[ INFO] ------------------------------------------------------------------------
-
[ INFO] Total time: 0.668 s
-
[ INFO] Finished at: 2019-07-25T16:04:20+08:00
-
[ INFO] ------------------------------------------------------------------------
-
[ ERROR] Plugin org.apache.maven.plugins:maven-clean-plugin:3.1.0 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-clean-plugin:jar:3.1.0: Could not transfer artifact org.apache.maven.plugins:maven-clean-plugin:pom:3.1.0 from/to public (http://******************.com/nexus/content/groups/public/): Cannot access http://******************.com/nexus/content/groups/public/ with type default using the available connector factories: BasicRepositoryConnectorFactory: Cannot access http://******************.com/nexus/content/groups/public/ using the registered transporter factories: WagonTransporterFactory: java.util.NoSuchElementException
-
[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
-
网上有不少解决办法,分别以下:svn
- 因为maven默认的下载服务器在国外,网络很差下载很差jar包,让修改maven_home/conf目录下的setting文件,增长阿里的下载镜像地址,而后从新下载插件;
- 删除插件在本地仓库中的目录,从新下载,不停的尝试,直到可行为止
- 等等等。。。。。。
小编在尝试上面的两种方式以后,最终的解决办法:测试
在cmd窗口进入到项目目录下,执行指令mvn clean package,而后就BUILD SUCCESS,试100次成功100次,回头再到eclipse中执行,也BUILD SUCCESS了ui
个种缘由我就不是很清楚,只是再也不相信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 文件就有问题,或者因为检出后本地的某些操做,也可能致使 这个文件出现异常,最终结果就是致使项目的构建发生各类问题。
排查其是否有问题的方法
一、能够在本地新建一个好用的maven项目,而后用其自动生成的 .classpath 文件,和故障项目的 文件比对。
二、能够直接使用上面文章中的例子
三、能够和同事好用的项目中的文件比对。