Creating and Handling JAR files

By: Reema sen Viewed: 153218 times  Printer Friendly Format    


A utility is used to generate a JAR file. Its syntax is shown here:

jar options files

Creating a JAR File

The following command creates a JAR file named Xyz.jar that contains all of the .class and .gif files in the current directory:

jar cf Xyz.jar *.class *.gif

If a manifest file such as Yxz.mf is available, it can be used with the following command:

jar cfm Xyz.jar Yxz.mf *.class *.gif

Tabulating the Contents of a JAR File

The following command lists the contents of Xyz.jar:

jar tf Xyz.jar

Extracting Files from a JAR File

The following command extracts the contents of Xyz.jar and places those files in the current directory:

jar xf Xyz.jar

Updating an Existing JAR File

The following command adds the file file1.class to Xyz.jar:

jar -uf Xyz.jar file1.class

Recursing Directories

The following command adds all files below directoryX to Xyz.jar:

jar -uf Xyz.jar -C directoryX *



Most Viewed Articles (in Java )

Latest Articles (in Java)

Comment on this tutorial