Java Quick Guide

 
 
This guide contains useful Java information.







Jar Tool.



Information
The JAR (Java ARchive) tool combines multiple files into a single Java Archive (JAR) file, which is a platform-independent file format. The JAR tool can also retrieve files from a JAR file. The JAR tool can be found in the Java 2 Standard Edition SDK. To use the JAR tool, you must install the Java 2 Standard Edition SDK. If the J2SE SDK is installed in a Windows environment the JAR tool (jar.exe) is located at %JAVA_HOME%\bin\.

The JAR format is used, because it:
  • supports compression (thus improving download time)
  • individual entries in a JAR file can be signed to authenticate their origin.
Detailed information in how to use the JAR tool, see:
http://java.sun.com/docs/books/tutorial/jar/basics/index.html

Usage: jar {ctxu} [vfm0M] [jar-file] [manifest-file] [-C dir] files ...

If any file is a directory then it is processed recursively. The manifest-file name and the jar-file name needs to be specified in the same order the "f" and "m" flags are specified.

The options can be found in the below mentioned table.
Note: Based on java version 1.4.0_03

Options Description
c create new archive
t list table of contents for archive
x extract named (or all) files from archive
u update existing archive
v generate verbose output on standard input
f specify archive file name
m include manifest information from specified manifest file
O 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


The examples below are based on the following situation:
directory c:\myapp\com\mobilefish contains files: test1.class, test2.class
directory c:\myapp\com\mobilefish\lib contains files: help1.class, help2.class

Example 1: Create new archive example1.jar
The content of jar file starts with directory com and must include all files:


Example 2: Create new archive example2.jar
The content of jar file starts with directory com and must only include files: help1.class and help2.class:


Example 3: Create new archive example3.jar
The content of jar file starts with directory com and must only include files: help1.class and test1.class:


Example 4: Display content of example3.jar




Example 5: Add files test2.class and help2.class into example3.jar (in their respective directories)


Example 6: Create new archive example6.jar
The content of jar file starts with directory com and must only include file: help1.class. The manifest.mf file should NOT be created:


Example 7: Create new archive example7.jar
Add in example7.jar the file help1.jar and put it in the root directory of the jar file (no subdirectories are created).

Example 8: Unpack archive example7.jar