Jar files are a way of packaging a java application as a single executable file.
A jar file can contain
bytecode (.class files) as well as data files, graphics images and other resources belonging to a java
file is ess
entially a zip file with special features. You can easily view the contents of a jar file by
renaming the file to .zip ( or adding the .zip extension) and the use software like WinZip of Windows
Zip file viewer.
Zip tools cannot create jar f
Jar files contains features not
implemented in standard zip tools.
The purpose of this document is to provide a brioef description of jar
files and to provide an example
how a executable application in the form of a jar file can be created.
structure of a jar file
The netbeans environment creates jar
iles whenever a project is
This example is
given for the .jar file provided by netbeans building the KeyboardReading example. You find the jar
file in your Project directory
in the subdirectory named dist, see below.
file is renamed with a .zip extension for easy viewing in WinXP.
file displays the package created in the keyboardreading example
Most of the features provid
ed by the jar format are contained within the folder META
INF folder contains metadata (information about the
file and the
required by the application itself is located within this folder.
The information is cont
aing in a file called MANIFEST.MF
is a plain text file with the
The format of the Manif
est.mf file is defined by jar.
This instruction are created by the NetBeans environment.
The information in the manifest is line
The key name/value pairs being
This provides the java environment with the instruction
s required to execute the application.
the class containing the public static void main(Stringarg) method.
Creating jar files
You create a jar file by using the tool jar.exe. jar.exe is a command
line tool located in the java bin
Locate you java installation directory and locat
e the bin/jar.exe file. Y
ou command tool
should have a path set to the java installation directory.
the help for creating the
Execute the command in your environment to get the help
contents given in english.
Suppose we have written an application where the class containing the m
ain method is named
StartClass (of StartClass.class) and the required files, including StartClass.class, are located in
a directory java.
Create the mani
fest file using Notepad or similar suitable tool. The manifest must contain at a
Create this file in the same directory as the class files.
Type the following command while in the directory java/
.jar manifest.txt *.class
The order of
is important. c
supply a filename for the application/jar
add a given manifest file
Something similar to the above will display.
The jar tool
creates a file
. You can execute this application by issuing the command
Configuring windows to execute
You java install procedure may already have provoded you with this particular feature. If this
case you shold not execute these instructions.
In the explorer interface select menu
With the jar filetype selected select
If the open action is no
nexistent select New
… If it exist select Edit…
In the edit field A
… navigate to your java installation directory.
Select the java
Add the parameters
jar "%1" %*
ar "%1" %*
jar "%1" %*
should be used if you would like to be able to execute console based applications.
This will associate .jar files with the java runtime environment.
.jar files w
You can execute you jar applica
file by double
clicking your .jar file or by
At a command prompt. The first statement will execute the application in a new process
ow in the console case), the second executes the application in the same console.