错误:通过SSH运行时找不到或加载不了主类org.testng.TestNG。

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

Error: Could not find or load main class org.testng.TestNG when running via SSH

问题

我有一个项目,使用以下命令运行:java -cp ".\target\classes;lib\*;" org.testng.TestNG ParallelTestXML.xml,它运行得很正常。我通过SSH上传了这个项目,想要在远程计算机上(一个AWS ec2实例)上运行它,但我得到了 Error: Could not find or load main class org.testng.TestNG 错误。尽管我在同一个 Project 文件夹中使用完全相同的命令,它仍然失败。

当所有依赖项都包含在 lib 文件夹内的 Project 文件夹中时,为什么会出现这种情况,导致它找不到 testNG 呢?我可以在本地无问题地运行这个项目。

甚至当我尝试仅运行Java类时,忽略 testNG 部分,像这样 java -cp "./target/classes/;lib/*" RealPackage.Controller,我会得到这个错误:Error: Could not find or load main class RealPackage.Controller

在这两种情况下,我在本地进行了测试,都正常工作。我通过SSH上传的项目就是整个项目;它应该是相同的,所以这些命令为什么不起作用真的让我感到困惑。

您可以看到两个项目位置具有相同的结构。左边是我的本地PC,右边是AWS服务器上的情况:
错误:通过SSH运行时找不到或加载不了主类org.testng.TestNG。

编辑:经过一段时间,我意识到这是因为我在Linux机器上尝试使用Windows语法。因此,现在我想到了在Linux机器上使用这个命令:java -cp .:/target/classes/:lib/* org.testng.TestNG ParallelTestXML.xml,但现在它无法找到位于 /target/classes 位置的类。

英文:

I have a project that I run using the following command:java -cp ".\target\classes;lib\*;" org.testng.TestNG ParallelTestXML.xml
and it runs just as it should. I uploaded this project via SSH and want to run it on the remote computer (an AWS ec2 instance), but I get Error: Could not find or load main class org.testng.TestNG. It fails even though I am using the same exact command in the same Project folder.

What could be causing this when all dependencies are included within the Project folder inside the lib folder so how can it not find testNG. I can run the project locally no problem.

I even get the same error when I try to run just the Java classes, ignoring the testNG part like this java -cp "./target/classes/;lib/*" RealPackage.Controller and I get this error: Error: Could not find or load main class RealPackage.Controller.

In both of these cases, I tested them locally and worked fine. The project I uploaded via SSH is this entire project; it should be identical so these is really confusing me that these commands don't work.

You can see that both project locations have the same structure. The Left is my local PC, the right is what is on the AWS server:
错误:通过SSH运行时找不到或加载不了主类org.testng.TestNG。

EDIT: So after some time I realized its because I was trying to use Windows sytnax on a Linux machine. So now I have come up with this for the Linux amchine: java -cp .:/target/classes/:lib/* org.testng.TestNG ParallelTestXML.xml and it now can't find the classes that are located in the /target/classes location.

答案1

得分: 0

原来,您列出类路径的顺序很重要。所以我只需重新排列它,然后它就可以工作了。

英文:

Turns out the order in which you list the classpath matters. So I just had to rearrange it and it worked.

huangapple
  • 本文由 发表于 2020年9月5日 00:28:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/63744909.html
匿名

发表评论

匿名网友

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

确定