blog

Home / DeveloperSection / Blogs / Executing a Java program using JAR file

Executing a Java program using JAR file

Devesh Kumar Singh2387 30-Oct-2015

How to create a JAR file in Command Prompt:

·         Start Command Prompt. 

Navigate to the folder that holds your class files;

C:\cd mywork 


Executing a Java program using JAR file

·   Set path to include JDK’s bin. For example;
C:\mywork> set path=c:\Program Files (x86)\Java\ldk1.8.0_31\bin 

Executing a Java program using JAR file

 

·    Compile your class(es);

C:\mywork> javac HelloWorld.java 


Executing a Java program using JAR file

 

·    Create a Manifest file and your Jar file;
C:\mywork> echo main-Class: Hello >manfest.txt
C:\mywork> jar cvfm Hello.jar manifest.txt HelloWorld.class
or
C:\mywork> jar cvfe Hello.jar Hello HelloWorld.class

This will create your manifest and jar file in the location where your java program is. 

·    Test your jar directly by typing the following command on your command prompt or simply double click the Hello.jar file from where it is saved.

C:\mywork> Hello.jar

or

C:\mywork> java –jar Hello.jar

This will run your java program using JAR file.


Updated 13-Mar-2018

Leave Comment

Comments

Liked By