英文:
Exception in thread "main" java.lang.NoClassDefFoundError in testng
问题
以下是你要翻译的内容:
我在测试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
我不确定如何更改我的类路径文件来解决这个问题。
<?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......");
}
}
没有pom文件,以下是现有的文件和文件夹结构。
英文:
I am getting the above error in my program while testing testNG. I also installed my testng plugin through help->install new.
I am aware that NoClassDefFoundError means that the class is present in the classpath at Compile time, but it doesn't exist in the classpath at Runtime.
Below is my stacktrace.
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
Im not sure on how to change my classpath file to solve the issue.
<?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>
My java class file is also in the src folder which looks like this.
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......");
}
}
There is no pom file and the below are the existing files and folder structure.
答案1
得分: 4
在 pom.xml
中添加缺失的 google-guice-core
依赖。
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>4.1.0</version>
</dependency>
或者从 这里 下载 JAR 文件,并将其添加到类路径中。
英文:
Add the missing google-guice-core
dependency in the pom.xml
.
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>4.1.0</version>
</dependency>
or download the jar from here and add it to the classpath.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论