java - 错误: Could not find or load main class error when compiling in eclipse and command prompt But works in intelliJIDEA

标签 java classpath

我一直面临这个简单的问题,但无法解决这个问题。在 Eclipse 中以及从命令提示符运行时都会出现此错误。

我知道这个问题在这里被问了很多次,但并没有安静地从其中任何一个中得到解决方案。

只是想了解一些事情。这是我拥有的这个简单的尝试程序。

package com;

public class Test {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.out.println("Hellooooooo");
    }

}

在 Eclipse 中我得到这个 Error: Could not find or load main class com.Test

现在当我从命令提示符尝试时。

C:\workSpaceLatest\Test\src\com>java Test
Error: Could not find or load main class Test

当我运行C:\workSpaceLatest\Test\src\com>javac Test.java时,没有错误也没有输出

enter image description here

但是在 IntelliIDEA 中它工作得很好。为什么会这样。 有人帮我理解一下这一点。

**P.S:向我指出具有最佳答案的任何帖子或问题。不过我还没找到。

最佳答案

由于您将 com 作为包,因此类名称将为 com.Test,因此要运行该类,请从 C:\workSpaceLatest\Test\src编译后的文件夹如下。

C:\workSpaceLatest\Test\src>java com.Test

enter image description here

注意:您可以像现在一样编译该类。

关于java - 错误: Could not find or load main class error when compiling in eclipse and command prompt But works in intelliJIDEA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59981353/

相关文章:

java - 在 Spring 的 Classpath 中发现 Plugin-JARS

eclipse - 在带有 Maven 的 Eclipse 中的 Tomcat 中使用 JavaCompiler 使用 webapp 类路径

maven - Intellij 14 未在类路径中添加 pom 依赖项

java - 编译时在类路径中找到类,但运行时找不到类

java - 最终字符串与最终整数

java - 如何从 HashMap 中仅打印前 10 个单词及其出现频率?

java - 在参数化语句中使用 SQL 函数

java - WEKA API LibSVM 类路径未找到

java - 无法在 hibernate 中删除 OneToMany 关系的实例

java - 在 Java/C++ 中创建类单例