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 

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
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.

  Modified On Mar-13-2018 03:59:42 AM

Leave Comment