我在 Eclipse 中创建了一个 java 程序。当我在 Eclipse 中运行程序时(“run as -> Java Application”),程序运行良好并且我有正确的输出。但是,当我尝试在命令行界面中运行该程序时,出现此错误:
Exception in thread "main"
java.lang.NoClassDefFoundError
:HelloWorld
(wrong name: helloworld/HelloWorld) Could not find the main class: HelloWorld. Program will exit.
类文件在目录 bin 中,我尝试使用以下命令运行它:
java HelloWorld
最佳答案
因为你的类在包 helloworld
中,你应该像这样运行它:
java helloworld.HelloWorld
还要确保“.”在你的类路径上。
关于java - 从命令行界面运行 Java 程序的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5934999/