zoukankan      html  css  js  c++  java
  • maven项目新检出后不编译爬坑记 及 mvn clean package报错 WagonTransporterFactory: java.util.NoSuchElementException 异常【我】

    从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

     

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
    本文链接:https://blog.csdn.net/Min_Monk/article/details/97271854

    在eclipse中执行clean package指令报错,错误信息如下:

    1. [INFO] Scanning for projects...
    2. [INFO]
    3. [INFO] --------------------------< com.demo:ws-demo >--------------------------
    4. [INFO] Building ws-demo 0.0.1-SNAPSHOT
    5. [INFO] -------------------------------[ bundle ]-------------------------------
    6. [INFO] ------------------------------------------------------------------------
    7. [INFO] BUILD FAILURE
    8. [INFO] ------------------------------------------------------------------------
    9. [INFO] Total time: 0.668 s
    10. [INFO] Finished at: 2019-07-25T16:04:20+08:00
    11. [INFO] ------------------------------------------------------------------------
    12. [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
    13. [ERROR] role: org.apache.maven.wagon.Wagon
    14. [ERROR] roleHint: http
    15. [ERROR] -> [Help 1]
    16. [ERROR]
    17. [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    18. [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    19. [ERROR]
    20. [ERROR] For more information about the errors and possible solutions, please read the following articles:
    21. [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException
    22.  

    网上有很多解决办法,分别如下:

    1.  由于maven默认的下载服务器在国外,网络不好下载不好jar包,让修改maven_home/conf目录下的setting文件,增加阿里的下载镜像地址,然后重新下载插件;
    2.  删除插件在本地仓库中的目录,重新下载,不停的尝试,直到可行为止
    3. 等等等。。。。。。

    小编在尝试上面的两种方式之后,最终的解决办法:

    在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、可以和同事好用的项目中的文件比对。

  • 相关阅读:
    moment JS 时间操作指南
    react 项目使用 echarts-wordcloud(文字云)
    moment实现计算两个时间的差值
    JS实现回到页面顶部的五种写法(从实现到增强)
    关于谷歌浏览器携带cookie失效解决方案
    Axios发送请求下载文件(重写二进制流文件)
    修改 input / textarea placeholder 属性的颜色和字体大小
    js实现数组浅拷贝和深拷贝
    JS中的可枚举属性与不可枚举属性
    物流管理
  • 原文地址:https://www.cnblogs.com/libin6505/p/11820059.html
Copyright © 2011-2022 走看看