Extracting

To examine your handiwork, you can use the -t option to list the contents of a JAR. Again, we use the -f option to specify the JAR name. As before, the -v option is also available.

C:\ jar -tvf GraphLayout.jar
   948 Tue Jun 03 15:29:48 EDT 1997 META-INF/MANIFEST.MF
   316 Wed Sep 18 12:16:52 EDT 1996 Edge.class
  3059 Wed Sep 18 12:16:52 EDT 1996 Graph.class
  5986 Wed Sep 18 12:16:54 EDT 1996 GraphPanel.class
   375 Wed Sep 18 12:16:54 EDT 1996 Node.class
     0 Wed Apr 16 08:28:38 EDT 1997 audio/
 21745 Wed Sep 18 12:16:56 EDT 1996 audio/computer.au
   759 Wed Sep 18 12:16:56 EDT 1996 audio/drip.au
 42068 Wed Sep 18 12:16:56 EDT 1996 audio/gong.au

But wait a minute! What is META-INF/MANIFEST.MF? It’s the manifest file, a special file that contains information about the rest of the JAR. I’ll talk about it soon.

To extract files from a JAR, use the -x option. The -f and -v options are available, as before. You can extract all the files or just specify a few, as we do here:

C:\ jar -xvf GraphLayout.jar Edge.class audio
 extracted: Edge.class
   created: audio\
 extracted: audio\computer.au
 extracted: audio\drip.au
 extracted: audio\gong.au

Conveniently, jar automatically recreates directory structure.

On the Win32 platform, you may have to reverse some of the slashes. For example, to extract just the computer.au file in the audio subdirectory, you would do this:

C:\ jar -xvf GraphLayout.jar audio\computer.au
 extracted: audio\computer.au

Even though a contents listing (using -t ) shows this file as ...

Get Java Cryptography now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.