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

Executing a Java program using JAR file

Java Java  Javac  Command line  JAR 
0 Comment(s)
 587  View(s)
Rate this:

Executing a Java program using JAR file:


How to create a JAR file in Command Prompt:

·         Start Command Prompt.
Navigate to the folder that holds your class files;
C:\cd mywork


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



·         Compile your class(es);

C:\mywork> javac HelloWorld.java



·         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
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
C:\mywork> java –jar Hello.jar

This will run your java program using JAR file.

Don't want to miss updates? Please click the below button!

Follow MindStick