Console compilation run. java file
First, enter java–version in cmd to determine if the Java environment variable is already well-equipped
Second, enter javac–version in cmd to determine if the JAVAC environment variable is already well-equipped
When you use the CD command to go to the path where you want to compile the. java file, compile the Java file with Javac Classname.java , and you will see that a. class file is generated;
Second, to run the. class file, you can enter the Java classname directly (without the suffix name);
If you want to generate a jar file, use the command jar CVF Classname.jar classname.class, the file name of the middle. Jar is customizable, and if you want to run the jar file, enter Java–jar directly. Classname.jar, but this is a possible "no Master manifest attribute" issue, the workaround is to open the Manifest.mf file in the. jar file, and if you do not main-class this line, add Main-class:classname, Note ClassName must have a space in front of it, and ClassName has the same name as the. class file. Then save, and then execute Java–jar classname.jar to run the jar file.
Finally, note that if the. java file contains the package name (for example, packages com;), you should make the current path fall back to the parent path of COM and run Java com.classname, but there is no solution for running the same jar file.
Detailed instructions for running Java programs in console compilation