java - 错误 : Could not find or load main class on running the java file

标签 java windows jar classpath

当我编译以下内容时,它会编译并创建一个 .class 文件。有效

javac -classpath abc.jar Abc.java

但是当我运行以下命令时:

java -classpath abc.jar Abc

它给出了这个错误:

Error: Could not find or load main class

我在 Windows 7 上使用 cmd。它适用于基本的 helloworld 示例,但不适用于其他示例。

最佳答案

它会覆盖类路径,因此您必须再次将当前目录添加到类路径

java -classpath abc.jar:. Abc

关于java - 错误 : Could not find or load main class on running the java file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25671262/

相关文章:

java - 将图像插入 JList

java - jar 文件外部的 ResourceBundles

Java 编译器错误 : "public type .. must be defined in its own file"?

windows - 用于在子文件夹中查找文件夹并获取路径的批处理脚本

Windows CMD/BATCH 保留最新的日期戳文件

java - 构造函数调用或 JFrame 的问题

Windows 在运行时删除 make 可执行文件。为什么?

java - 尝试将 rtf 文件从 Jar 读取到 JEditorPane;在 Netbeans 中工作,而不是在 Jar 中工作

java - 使用java类加载jar中存在的Applicationcontext.xml

java - 作为 jar 文件运行时返回字符串作为 JSON 响应失败并显示 500 状态代码