Exception in thread “main” java.lang.NoClassDefFoundError in testng

huangapple go评论80阅读模式
英文:

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 &quot;main&quot; java.lang.NoClassDefFoundError: com/google/inject/Stage
	at org.testng.internal.Configuration.&lt;init&gt;(Configuration.java:33)
	at org.testng.TestNG.init(TestNG.java:216)
	at org.testng.TestNG.&lt;init&gt;(TestNG.java:200)
	at org.testng.remote.AbstractRemoteTestNG.&lt;init&gt;(AbstractRemoteTestNG.java:17)
	at org.testng.remote.support.RemoteTestNG6_12.&lt;init&gt;(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.

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;classpath&gt;
	&lt;classpathentry kind=&quot;con&quot; path=&quot;org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7&quot;&gt;
		&lt;attributes&gt;
			&lt;attribute name=&quot;module&quot; value=&quot;true&quot;/&gt;
		&lt;/attributes&gt;
	&lt;/classpathentry&gt;
	&lt;classpathentry kind=&quot;src&quot; path=&quot;src&quot;/&gt;
	&lt;classpathentry kind=&quot;con&quot; path=&quot;org.testng.TESTNG_CONTAINER&quot;/&gt;
	&lt;classpathentry kind=&quot;output&quot; path=&quot;bin&quot;/&gt;
&lt;/classpath&gt;

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(&quot; RC server starting......&quot;);
	}
	
	public void testLogIn() {
		System.out.println(&quot; Test is executing......&quot;);
	}
	
	@AfterTest
	public void ShutDownRCServer() {
		System.out.println(&quot; RC server stopping......&quot;);
	}
	
}

There is no pom file and the below are the existing files and folder structure.
Exception in thread “main” java.lang.NoClassDefFoundError in testng

答案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.

&lt;dependency&gt;
    &lt;groupId&gt;com.google.inject&lt;/groupId&gt;
    &lt;artifactId&gt;guice&lt;/artifactId&gt;
    &lt;version&gt;4.1.0&lt;/version&gt;
&lt;/dependency&gt;

or download the jar from here and add it to the classpath.

huangapple
  • 本文由 发表于 2020年4月5日 15:13:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/61039218.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定