Error: A JNI error has occurred, please check your installation and try again. Using Eclipse, TestNG

Viewed 8813

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");

}

}

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
1 Answers

Not sure how do you setup your eclipse project, but according to the error msg, the TestNG is missing on runtime classpath.

  1. correctly setup your eclipse project and classpath.

    1a. it's recommended to use dependency management tool like Maven or Gradle.

    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.

  2. right click on your test class, select "Run As -> TestNG"
  3. if the error remain, please double check the classpath of the launch configuration: "Run -> Run configurations..." -> navigate to the right launch configuration -> switch to tab "Classpath", double check TestNG and the dependencies are in the entries list.

If still can't solve the issue, please attach a reproducible sample project.

Related