java - 在命令提示符下执行 java runnable jar 时出错。错误:reflect.invocationtargetexception
问题描述
我创建了一个 Maven 项目并使用 testng 在其中编写测试。我还使用 maven 创建了一个可执行 jar,但是在命令提示符下使用项目中使用的参数执行 jar 时出现错误。我实际上无法弄清楚错误。请帮我解决一下这个。
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
我的项目主类代码(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();
}
}
我也尝试过重新安装java、testng,然后我运行了这个项目,但我得到了同样的错误。到目前为止,我无法弄清楚实际错误。所以请帮我找出错误并完成这项任务。
提前致谢 :)
解决方案
推荐阅读
- loops - 在嵌套循环中添加动态主机时 Ansible include_tasks 出错
- couchdb - 高级查询 - 部分匹配
- python-3.x - 将非结构化的txt文件读入数据框
- r - 如何修复:“CA(dt, graph = FALSE) 中的错误:以下变量不是定量 Var1”
- c# - Protobuf-net 反序列化问题
- iframe - 如何修复“阻止来自“https://example.org”的框架访问跨域框架。”
- python - 如何创建一个新的 jupyter 笔记本单元并使用笔记本服务器 rest api 或 python 代码更新单元?
- python - Python:turtle 或 tkinter 不理解 UP
- go - 如果没有其他要执行的语句,为什么 time.Sleep 不起作用?
- angular - 如何在拦截器Angular 8中传递用户ID