错误:发生了JNI错误,请检查您的安装并重试。使用Eclipse,TestNG [英] Error: A JNI error has occurred, please check your installation and try again. Using Eclipse, TestNG
问题描述
在Mac OS上使用Eclipse,我试图运行简单的代码来测试一个testNG代码(后来与Jenkins一起使用):
Using Eclipse on Mac OS, I'm trying to run simple code to test one testNG code(later to use with Jenkins):
package demoJenkins;
import org.junit.Test;
public class DemoJenkinsJobs {
@Test
public void testJenkins(){
System.out.println("Welcome to Jenkins world");
}
}
首先我转换将其添加到TestNG,然后以TestNG的身份运行testing.xml,但是每次尝试时都会出现此错误(我已经添加了jcommander.jar和bash-1.3.0.jar):
First I convert it to TestNG then I run the testing.xml as TestNG, but every time I try I get this error(I already added jcommander.jar and bash-1.3.0.jar):
Error: A JNI error has occurred, please check your installation and
try again
Exception in thread "main" java.lang.NoClassDefFoundError:
org/testng/TestNGException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at
sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at
sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException:
org.testng.TestNGException
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
推荐答案
不确定如何设置eclipse项目,但根据错误消息msg,运行时类路径中缺少TestNG。
Not sure how do you setup your eclipse project, but according to the error msg, the TestNG is missing on runtime classpath.
-
正确设置Eclipse项目和类路径。
correctly setup your eclipse project and classpath.
1a。建议使用Maven或Gradle之类的依赖管理工具。
1a. it's recommended to use dependency management tool like Maven or Gradle.
1b。否则,您需要将TestNG添加到您的项目中:右键单击您的项目->构建路径->添加库->选择 TestNG->现在,您将在Project Explorer视图中看到TestNG及其依赖项。
1b. otherwise, you need to add TestNG to your project: right click your project -> Build Path -> Add Libraries -> select "TestNG" -> now you will see TestNG and it's dependencies jars on the Project Explorer view.
如果仍然无法解决问题,请附上可复制的示例项目。
If still can't solve the issue, please attach a reproducible sample project.
这篇关于错误:发生了JNI错误,请检查您的安装并重试。使用Eclipse,TestNG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!