在测试testNG时,我的程序出现了上述错误。我也通过help->install new安装了我的testng插件。
我知道NoClassDefFoundError意味着该类在编译时存在于类路径中,但在运行时不存在于类路径中。
以下是我的堆栈跟踪。
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/inject/Stage
at org.testng.internal.Configuration.<init>(Configuration.java:33)
at org.testng.TestNG.init(TestNG.java:216)
at org.testng.TestNG.<init>(TestNG.java:200)
at org.testng.remote.AbstractRemoteTestNG.<init>(AbstractRemoteTestNG.java:17)
at org.testng.remote.support.RemoteTestNG6_12.<init>(RemoteTestNG6_12.java:18)
at org.testng.remote.support.RemoteTestNGFactory6_12.createRemoteTestNG(RemoteTestNGFactory6_12.java:16)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:67)
Caused by: java.lang.ClassNotFoundException: com.google.inject.Stage
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 7 more
我不确定如何更改我的classpath文件来解决这个问题。
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.testng.TESTNG_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>
我的Java类文件也在src文件夹中,其目录结构如下。
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
public class ScreencastTestClass {
@BeforeTest
public void StartRCServiver() {
System.out.println(" RC server starting......");
}
public void testLogIn() {
System.out.println(" Test is executing......");
}
@AfterTest
public void ShutDownRCServer() {
System.out.println(" RC server stopping......");
}
}