Site icon Narayana Tutorial

how to create and extract jar and war file in windows

java

In this post, we can learn how to create and extract jar and war files in windows command prompt. We can create executable jar with Main class and MANIFEST file by using java commands in windows. In the same way we can create/extract war file by using java commands in windows.

 

Create Jar file without Main class

D:\NarayanaTutorial>jar cvf <file-name>.jar *  

OR

D:\NarayanaTutorial>jar cvf <file-name>.jar *.class

C : Create

V : Verbose

F : Jar file name

 

Create Jar file with manifest file including dependency jars and main class

First of all we should create a manifest file with any name like manifest.txt and then add the required dependency jars location and main class as follows.

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.1
Created-By: 1.7.0_67-b01 (Oracle Corporation)
Main-Class: EmailTest
Class-Path: lib/x1.jar lib/antlr-2.7.7.jar lib/x2.jar lib/x3.jar

Create text file with the name of manifest.txt and then add above content. After creation of file, you have to execute the following command.

D:\NarayanaTutorial>jar cvfm <file-name>.jar manifest.txt *.class

 

Create Jar file with only main class

D:\NarayanaTutorial>jar cvfe <file-name>.jar Narayanatutorial *.class

 

Execute the Jar file

D:\NarayanaTutorial>java -jar <jar-file-name>.jar

 

Create War file

D:\NarayanaTutorial>jar -cvf <war-file-name>.war *

* (asterisk) symbol indicates, it signifies that all the files of this directory (including sub directory).

 

Extract War file

D:\NarayanaTutorial>jar -xvf <war-file-name>.war