Detailed instructions for running Java programs in console compilation

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.