[java] After compiling under windows dos, there is a problem that the main class cannot be found or loaded

Under the premise that the environment variables, jdk version, etc. are correct.

The reason for this error is that the main class with the main method runs without the package name after javac.

E.g:

There is C:\test\src\com\test\java\1.java (there is a main method, the package name is "com.test.java") C:\test\src\com\test\java\2.java


编译:C:\test\src\com\test\java> javac -d . *.java


Run: C:\test\src\com\test\java> java 1 (it is wrong, it will report "cannot find or load main class");


Run: C:\test\src\com\test\java > java com.test.java.1 (is correct)


The final reason I guess is that java distinguishes classes based on package names. The same file name is not the same under different packages, so the path must be correct. Same as andorid.


At the same time, welcome the guidance of God~

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325856433&siteId=291194637