[Note] After compiling the idea, windows and mac execute the java compiled file on the cmd command terminal or terminal terminal, and an error occurs: the main class HelloWorld cannot be found or cannot be loaded

Due to the error caused by adding the package name when editing the idea, the solution:

Method 1: Edit the HelloWorld.java file with the command in the terminal, remove the package com.junyi in the first line; save:
insert image description here
compile it in the current directory of the HelloWorld.java file

Compile the java file:

javac HelloWorld.java

Run the compiled file:

java HelloWorld

Method 2:
Without modifying the file, move the current location to the current directory of the compiled package name, the directory where the com folder is stored, and execute the following command:

java com.junyi.HelloWorld

insert image description here

Guess you like

Origin blog.csdn.net/qq_41619841/article/details/123125637