I have created a maven project and writing tests in it using testng. I have also created an executable jar using maven but getting error when executing the jar in command prompt with the arguments that are used in project. I could not actually figure out the error. Please help me with this.
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:61)
Caused by: java.lang.NoClassDefFoundError: org/testng/TestNG
at mypackage.App.main(App.java:40)
... 5 more
Caused by: java.lang.ClassNotFoundException: org.testng.TestNG
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 6 more
command prompt error image in this link
My project Main class codes(App.java)
public class App {
public static String testdataExcel;
public static Properties props = null;
public static Properties loadPropertyFile(String filepath) throws IOException {
FileInputStream stream = new FileInputStream(filepath);
props = new Properties();
props.load(stream);
return props;
}
public static void main(String[] args) throws IOException, InterruptedException {
//Receiving arguments from command prompt
String Filename = args[0];
testdataExcel = args[1];
loadPropertyFile(Filename);
TestNG testng = new TestNG();
testng.setTestClasses(new Class[] { LoginPage.class, testclass2.class,
testclass3.class, testclass4.class,
testclass5.class, testclass6.class });
testng.run();
}
}
I have tried to reinstall java, testng as well and then i ran the project but i am getting same error. i could not figure out actual error so far. so kindly help me to find the error and complete this task.
Thanks in advance :)