JAR File Format and 'jar' Tool
Part:
1
2
3
4
5
This chapter describes:
- JAR File Format
- "jar" Tool
- hello.jar - My First JAR File
- JAR Files Are ZIP Files
- What Is "manifest"?
- Adding "manifest" to JAR Files
- Using JAR Files in Class Paths
- Creating Executable JAR Files
JAR File Format
JAR (Java Archive): A file format that compresses many files into a single package file. A JAR may
contain additional package attributes and supporting data. It has some interesting features:
- It uses the standard ZIP algorithm for compression.
- Package attributes and supporting data are stored as files in a special directory called META-INF.
The main purpose of a JAR file is to aggregate your .class files, not your .java files, into a single file
to distribute them to your customers. A JAR file can be directly included in the class path if you want to
access those class files in the JAR file. No need to extract those class files into Java class directories.
"jar" Tool
"jar": A command line tool for managing JAR files. "jar" is distributed as part of the Sun JDK package.
It has some interesting features:
- It can create, update or extract a JAR file.
- ZIP compression is optional.
"jar" command syntax:
Create jar file
jar c[v0M]f jarfile inputfiles
jar c[v0]mf manifest jarfile inputfiles
Update jar file
jar u[v0M]f jarfile inputfiles
jar u[v0]mf manifest jarfile inputfiles
Extract jar file
jar x[v]f jarfile [inputfiles]
List table of contents of jar file
jar t[v]f jarfile [inputfiles]
where:
- "c" - Creates a new JAR file.
- "v" - Generates verbose output to standard output.
- "0" - Specifies no compression.
- "M" - Specifies no manifest file.
- "f" - Specifies the JAR file name.
- "m" - Specifies the manifest file name.
- "u" - Updates a JAR file.
- "x" - Extracts files out of a JAR file.
- "t" - Displays the table of contents of a JAR file.
"jar" command is supported by the file, \j2sdk1.5.0\bin\jar.exe, if you installed JDK as in my previous chapter.
(Continued on next part...)
Part:
1
2
3
4
5
|