java - 从命令行界面运行 Java 程序的问题

标签 java

我在 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/

相关文章:

java - ArrayIndexOutOfBoundsException - 命令行参数

java - 正则表达式:包含一个词,不包含另一个词

java - 确定网络类型是 2G、3G 还是 4G

java - 在不知 Prop 体类型的情况下实例化对象

java - 在Java中生成一组唯一的随机数

java - 将十六进制字符串转换为类对象

java - equals() 和compareTo() 的重写实现从未被调用

java - 建议一个 JMS 提供者(针对 Java 平台)

java - mapstruct:如何从mapstruct中对象的属性构造字符串?

java - Android relase APK无法加载 Activity