[英]Java: Could not find or load main class
Could not find or load main class CLASSNAME
找不到或加载主类CLASSNAME
java -cp "Path to MAIN class" "MAINCLASSNAME"
java -cp“主类的路径”“ MAINCLASSNAME”
When I copy and paste the path, it is correct and when I go to the path and run the command it works fine. 当我复制并粘贴路径时,它是正确的;当我转到路径并运行命令时,它可以正常工作。
So can anyone help me and tell me what is going on here and how to fix it? 那么谁能帮助我,告诉我这里发生了什么以及如何解决?
java -cp /usr/home/dir1/2014Dir/Team1/Problem1/05:09:55/ Prob1
Error: Could not find or load main class Prob1
$
ls -l /usr/home/PCWSA/2014ConDir/Team1-14/Problem1/05:09:55/03-21-14_07.05.17:
total 4
-rw-r--r-- 1 PCWSA PCWSA 1359 Mar 21 07:05 Prob1.class
Example to run the program .. 运行程序的例子..
To compile the program go to src directory in command line and type the following 要编译程序,请在命令行转到src目录并键入以下内容
C:/blah/src > javac com\\sample\\MAINCLASSNAME.java C:/ blah / src> javac com \\ sample \\ MAINCLASSNAME.java
To run the program use the following command 要运行该程序,请使用以下命令
C:/blah/src > java -cp . C:/ blah / src> java -cp。 com.sample.MAINCLASSNAME
com.sample.MAINCLASSNAME
Use the command javac -d to specify the place where u want to generate your class files .. Then run the java command from that directory. 使用命令javac -d指定要在其中生成类文件的位置。然后从该目录运行java命令。
Based on your last edit, it looks like you're trying find your .class file in the wrong directory 根据您的上一次编辑,您似乎正在尝试在错误的目录中找到.class文件
You're trying to execute it on: 您尝试在以下位置执行它:
/usr/home/dir1/2014Dir/Team1/Problem1/05:09:55/
But the file is on: 但是文件已打开:
/usr/home/PCWSA/2014ConDir/Team1-14/Problem1/05:09:55/03-21-14_07.05.17:
So just use that directory instead: 因此,只需使用该目录即可:
java -cp "/usr/home/PCWSA/2014ConDir/Team1-14/Problem1/05:09:55/03-21-14_07.05.17:" Prob
So I figured what the problem was! 所以我想出了问题所在! My path to the MAINCLASS contained dots '.'
我通往MAINCLASS的路径包含点“。”。 and that was causing the issue, when I renamed the folders it worked fine.
这就是导致此问题的原因,当我重命名文件夹时,它可以正常工作。 I hope this is going to be helpful.
我希望这会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.