jar.exe : Java Glossary

go to home page J words local find full screen, hide local find menu Google search web for more information on this topic jump to foot of page translate this page with Babelfish punctuation 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z (all) ©1996-2009 Roedy Green, Canadian Mind Products
jar.exe
Sun’s tool for building jar files.

Usage:

jar {ctxu}[vfm0M] [jar-file] [manifest-file] [-C dir] files ...
Option Meaning
c create new jar rather than update existing one.
i create an index in this jar of all the jars in the manifest Class-Path for faster loading. This won’t buy you much in a single jar situation, since evvery zip/jar already has an index for that archive tacked on the end. I found that -i did not work combined with -fc.
t list table of contents for jar.
x extract named (or all) files from jar.
u update existing jar.
v generate verbose output on standard output.
f specify jar file name (always needed). If you leave it out jar.exe will idiotically spray the binary contents of the created jar to the console.
m include manifest information from specified manifest file.
0 store only; use no ZIP compression.
M do not create a manifest file for the entries.
i generate index information for the specified jar files.
-C change to the specified directory and include the following file.
For some reason the fool thing insists you collapse flags, e. g. You must say:
REM Examine the contents of a jar, and test integrity
jar.exe -tf myjar.jar

REM For a sorted list, use my JarLook utility
REM available from http://mindprod.com/products1.html#JARLOOK
java.exe -jar jarlook.jar myjar.jar
rather than:
REM With separate flags, jar.exe will NOT work.
jar.exe -t -f myjar.jar
If any file is a directory then it is processed recursively. The manifest file name and the archive file name needs to be specified in the same order that the 'm' and 'f' flags are specified. You will be safe if you always put the options in standard order and put the files in standard order.

Prepare a skeleton manifest main.mft file to define your main class that looks like this:

Main-Class com.mindprod.Bulk
Specify all the qualification you want included in the jar to get the proper package names and set your default directory appropriately : e.g.

Note that the following technique will not work. You will get NoClassDefFoundErrors.

Jar.exe has no intelligence or common sense. It will mindlessly create jars that have packages and member names out of sync that have no chance of working without even a warning message.

Avoid C:\ on the class files to be included, or the C:\ may be improperly included as part of the package name. WinZip will disguise the damage, but JarLook will show it to you.

The jar.exe file itself lives in 

jar.exe :

forjar.list

If you get too many jar files to include on the command line, you can put the overflow in a forjar.list file like this:
/com/mindprod/jdisplay/JDisplay$1.class
/com/mindprod/jdisplay/JDisplay$2.class
/com/mindprod/jdisplay/JDisplay$3.class
/com/mindprod/jdisplay/JDisplay$4.class
/com/mindprod/jdisplay/JDisplay.class
/com/mindprod/jdisplay/Keyword.class
Unlike the command line you can’t use wildcards and you must use / instead of \. This seems odd until you realise the command line arrives at jar.exe with wildcards pre-expanded. It has not inherent ability to understand them. Further you can’t recurse, but references to other @something.lists in your forjar.list You are stuck spelling all the classes and their inner classes out longhand. You invoke it all one line like this:

You will waste hundreds of hours maintaining lists of files that need to go in each jar. If you do this manually, you will forever be forgetting some class or throwing in the kitchen sink needlessly. There is automated help do select just the class files needed called genjar which works with ant, but, unfortunately, there is no corresponding tool to help with resources. However, there are ways of reducing the number of resource files (see Cramfull), and once you have the classes right, adding the corresponding resources is fairly mechanical.

Unlike zip files, the timestamps in jars created by jar.exe do not reflect the time the corresponding element file was last updated, but rather the time the element was added to the jar file.

Starting in JDK 1.5, you can super-compress jar files using pack200.exe. This will optionally remove debug information, and compress the jar as a whole.

Learning More

Sun’s JDK Tool Guide to jar.exe for Windows : available:
Sun’s JDK Tool Guide to jar utility on Solaris : available:
Sun’s JDK Technote Guide on jar spec : available:
Sun’s JDK Tool Guide to pack200.exe : available:


CMP homejump to top You can get the freshest copy of this page from: or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror)
http://mindprod.com/jgloss/jarexe.html J:\mindprod\jgloss\jarexe.html
CMP logofeedback Please email your feedback for publication, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : feedback email
mindprod.com IP:[65.110.21.43]
view BlogYour face IP:[38.107.191.109]
You are visitor number 51,365.