Java程序在IDE上运行,但不能在终端上运行



我有一个简单的Java代码:

package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
System.out.println("Please enter number of the days");
Scanner scanner = new Scanner(System.in);
int days = scanner.nextInt();
System.out.println("The number of seconds in the entered days number is "+days*86400);
}
}

文件夹结构为:srccomcompany

文件夹company中有Main.javaMain.class文件。

当我在IDE中运行应用程序时,当我试图在终端上运行它时,我得到:

错误:无法找到或加载主类main .class产生原因:java.lang.ClassNotFoundException: Main.class

以下列任何一种方式执行命令

  • From insidecompanyfolder:
java Main.class
  • From insidesrcfolder:
java com.company.Main.class
java.com.company.Main

给出相同的错误。

怎么了?

编译Java文件生成一个类:

javac filename.java

执行生成的类:

java文件

例子

javac Main.java

java主要

详细的答案可以在这里找到我如何在Windows上从命令行运行Java程序?

相关内容

最新更新