在运行pom.xml时获取org.testng的pOM:testng:jar:5.14.3无效且java.lang.NoClassDefFoundError

时间:2018-05-25 10:27:42

标签: java maven

在运行pom.xml时获取java.lang.NoClassDefFoundError,我已经更新了maven依赖项中的maven surefire插件以及更新的maven版本但仍然收到错误,

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building eGem 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for org.testng:testng:jar:5.14.3 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] The POM for org.testng:testng:jar:5.14.4 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] The POM for org.testng:testng:jar:5.14.5 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] The POM for com.beust:jcommander:jar:1.66 is missing, no dependency information available
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ eGem ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 13 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) @ eGem ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ eGem ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 12 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.5.1:testCompile (default-testCompile) @ eGem ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ eGem ---
[WARNING] Error injecting: org.apache.maven.plugin.surefire.SurefirePlugin
java.lang.NoClassDefFoundError: org/apache/maven/surefire/util/NestedCheckedException
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)

1 个答案:

答案 0 :(得分:0)

尝试添加配置部分并查看它是否有效,或者在调试模式下运行maven以进行进一步调试。

<project>
      [...]
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.21.0</version>
            <configuration>
              <useSystemClassLoader>false</useSystemClassLoader>
            </configuration>
          </plugin>
        </plugins>
      </build>
      [...]
    </project>

调试类路径问题 以下是一些尝试的一般提示:

  • 使用--debug(或等效地,-X)运行Maven以获得更详细的信息 输出检查forkCount。如果forkCount = 0(或forkMode = never,则为 不推荐使用的版本),不可能使用系统类 加载器或普通的旧Java类路径;我们必须使用孤立的 班级装载机。
  • 如果您使用的是默认值,请使用SystemClassLoader = true和 useManifestOnlyJar =假。在那种情况下,看看生成的 仅限清单的Surefire引导程序JAR。打开它(它只是一个拉链)和 读它的清单。
  • 使用-Dmaven.surefire.debug运行Maven,并附加到运行中 使用调试器进行处理。