Previous | Next | Trail Map | The Java Archive (JAR) File Format | Contents

Using JAR Files: The Basics

This lesson will show you how to perform basic operations with JAR files. JAR files are packaged with the ZIP file format, so you can use them for "ZIP-like" tasks such as lossless data compression, archiving, decompression and archive unpacking.

These are, in fact, among the most common uses of JAR files, and you can realize many JAR-file benefits using only these basic features. For example, packaging multi-class applets into a single JAR file can dramatically decrease applet download time.

Even if you want to take advantage of advanced functionality provided by the JAR file format such as electronic signing, you'll first need to become familiar with the fundamental operations.

To perform basic tasks with JAR files, you use the JavaTM Archive Tool provided as part of the Java Development Kit. Because the Java Archive tool is invoked by using the jar command, for convenience we'll call it the "Jar tool".

This lesson will show you how to use the Jar tool, with examples for each of its basic features:

In addition, this lesson contains a section on Running JAR-Packaged Software that shows you how to invoke applets and applications that are packaged in JAR files.

As a synopsis and preview of some of the topics to be covered in this lesson, the following table summarizes common JAR-file operations:

OperationCommand
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
jre -cp app.jar MainClass
To invoke an applet packaged as a JAR file
<applet code=AppletClassName.class
        archive="JarFileName.jar"
        width=width height=height>
</applet>

Some of the more advanced features offered by the JAR file format such as package sealing and electronic signing are made possible by the JAR file's manifest, a special file that JAR files contain. In the final section of this lesson, Understanding the Manifest, you'll find basic information about the structure and uses of the manifest file.

Additional References

The documenation for the Java Development Kit includes reference pages for the Jar tool:


Previous | Next | Trail Map | The Java Archive (JAR) File Format | Contents