Using JAR Files: The Basics

This page is an abbreviated form of  http://java.sun.com/docs/books/tutorial/jar/basics/index.html

Operation Command
To create a JAR file jar cf jar-file input-file(s)
To view the contents of a JAR file jar tf jar-file
To extract the contents of a JAR file jar xf jar-file
To extract specific files from a JAR file jar xf jar-file archived-file(s)
To run an application packaged as a JAR file
(version 1.1)
jre -cp app.jar MainClass
To run an application packaged as a JAR file
(version 1.2 -- requires Main-Class
manifest header)
java -jar app.jar
To invoke an applet packaged as a JAR file
<applet code=AppletClassName.class
archive="JarFileName.jar"
width=width height=height>
</applet>

Creating a JAR File

This section shows you how to use the Jar tool to package files and directories into a JAR file.

Viewing the Contents of a JAR File

You can display a JAR file's table of contents to see what it contains without actually unpacking the JAR file.

Extracting the Contents of a JAR File

You can use the Jar tool to unpack a JAR file. When extracting files, the Jar tool makes copies of the desired files and writes them to the current directory, reproducing the directory structure that the files have in the archive.

Modifying a Manifest File

This section shows you a couple of ways that you can modify the contents of a JAR file's manifest. You might want to modify the manifest, for example, to enable special JAR-file functionality.