Oct 10, 2018

[HDGEM] How to run java program from the command line


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 <MainClass> TheJavaFile.class
  5. To run the Jar File
    java -jar TheJavaFile.jar
  6. Or
  7. java -cp TheJavaFile.jar:/path/to/other/lib/* <MainClass>


--
Posted By Blogger to HDGEM at 3/08/2017 01:55:00 PM