首页 > 解决方案 > 在运行 pom.xml 时获取 org.testng:testng:jar:5.14.3 的 POM 无效和 java.lang.NoClassDefFoundError

问题描述

在运行 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)

标签: javamaven

解决方案


尝试添加配置部分,看看它是否有效,或者在调试模式下运行 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 类路径;我们必须使用一个隔离的类加载器。
  • 如果您使用默认值,useSystemClassLoader=true 和 useManifestOnlyJar=false。在这种情况下,请查看生成的仅清单 Surefire 引导程序 JAR。打开它(它只是一个 zip)并阅读它的清单。
  • 使用 -Dmaven.surefire.debug 运行 Maven,并使用调试器附加到正在运行的进程。

推荐阅读