"main"线程中的异常:在TestNG中发生了java.lang.NoClassDefFoundError错误

3

在测试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......");
    }

}

缺少pom文件,以下是现有的文件和文件夹结构。 enter image description here


1
请问您能否添加异常的堆栈跟踪信息? - Anish B.
1
在Eclipse中,配置是通过IDE菜单完成的。请参见菜单_Run_中的项目___Run Configurations...___。在这里,您可以配置运行时类路径(而不是构建类路径)。当然,如果您使用的是大于8的Java版本,则可能需要配置模块路径而不是类路径。 - Abra
1
@AnishB。已添加。 - Codeninja
请添加pom.xml文件。 - Anish B.
1
@AnishB,请查看我的更新问题。 - Codeninja
1个回答

4
pom.xml 中添加缺失的google-guice-core 依赖项。
<dependency>
    <groupId>com.google.inject</groupId>
    <artifactId>guice</artifactId>
    <version>4.1.0</version>
</dependency>

或者从这里下载jar包,并将其添加到类路径中。

1
还没有。在“运行配置->类路径”中,“添加”按钮被禁用了。 - Codeninja
1
@ShaviPathirana 不要这样做!!右键单击项目->打开属性->打开Java Build Path->点击库->点击添加外部jar或添加jar(根据您保存jar文件的位置而定),而不是从“运行配置”中添加。 - Anish B.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接