The jar Tool

Sun's JDK contains a simple command-line program called jar that packages a set of files or a directory structure into a JAR file. Its syntax is modeled after the Unix tar command. For instance, to verbosely compress the directory com into the file javaio.jar with the manifest file javaio.mf, you would type the following command line:

% jar cvmf javaio.mf javaio.jar com added manifest adding: com/ (in=0) (out=0) (stored 0%) xsadding: com/elharo/ (in=0) (out=0) (stored 0%) adding: com/elharo/io/ (in=0) (out=0) (stored 0%) adding: com/elharo/io/StreamCopier.class (in=887) (out=552) (deflated 37%) adding: com/elharo/io/NullOutputStream.class (in=374) (out=225) (deflated 39%) adding: com/elharo/io/RandomInputStream.class (in=792) (out=487) (deflated 38%) adding: com/elharo/io/NullOutputStream.java (in=263) (out=149) (deflated 43%) adding: com/elharo/io/StreamCopier.java (in=764) (out=377) (deflated 50%)

This creates a file named javaio.jar. To extract files, change cvmf (c reate v erbose with m anifest f ile) to xvf (ex tract v erbose f ile). If you don't care to see each file as it's added or extracted, you can omit the v argument:

% jar xf javaio.jar

You can also use any other zip tool to create or unpack JAR archives. However, you'll have to include the META-INF/MANIFEST.MF file manually.

The JDK also includes a jarsigner tool that digitally signs JAR archives and verifies JAR archives signed by others using a public key system.

Категории