How do I run a Java program from the command line on Windows?

后端 未结 12 1670
广开言路
广开言路 2020-11-22 03:03

I\'m trying to execute a Java program from the command line in Windows. Here is my code:

import java.io.File;
import java.io.FileInputStream;
import java.io.         


        
12条回答
  •  [愿得一人]
    2020-11-22 03:48

    To complete the answer :

    1. The Java File

      TheJavaFile.java
      
    2. Compile the Java File to a *.class file

      javac TheJavaFile.java
      
      • This will create a TheJavaFile.class file
    3. Execution of the Java File

      java TheJavaFile
      
    4. Creation of an executable *.jar file

      • You've got two options here -

        1. With an external manifest file :

          • Create the manifest file say - MANIFEST.mf

          • The MANIFEST file is nothing but an explicit entry of the Main Class

          • jar -cvfm TheJavaFile.jar MANIFEST.mf TheJavaFile.class

        2. Executable by Entry Point:

          • jar -cvfe TheJavaFile.jar TheJavaFile.class
    5. To run the Jar File

      java -jar TheJavaFile.jar
      

提交回复
热议问题