Let’s use jar to archive the files that make up the GraphLayout example applet that comes with the JDK 1.1. First, let’s look at the files in that directory:

C:\ dir

 Volume in drive C is BUENDIA
 Volume Serial Number is 1929-10EE
 Directory of C:\jdk1.2beta2\demo\GraphLayout

.              <DIR>        04-16-97  8:28a .
..             <DIR>        04-16-97  8:28a ..
EDGE~1   CLA           316  09-18-96 12:16p Edge.class
GRAPH~1  CLA         3,059  09-18-96 12:16p Graph.class
GRAPH~1  JAV         9,503  12-06-96 10:14a
GRAPHP~2 CLA         5,986  09-18-96 12:16p GraphPanel.class
NODE~1   CLA           375  09-18-96 12:16p Node.class
EXAMPL~1 HTM           415  09-18-96 12:16p example1.html
EXAMPL~2 HTM           241  09-18-96 12:16p example2.html
EXAMPL~3 HTM           619  09-18-96 12:16p example3.html
EXAMPL~4 HTM           283  09-18-96 12:16p example4.html
AUDIO          <DIR>        04-16-97  8:28a audio
         9 file(s)         20,797 bytes
         3 dir(s)     222,429,184 bytes free

All the applet needs to run are the .class files and the sound files contained in the audio directory.

You can create a JAR using the -c option. By default, jar sends data to standard output. For most commands, though, you can use the -f option to specify a destination file. In this case, we want to specify the name of the destination JAR as well as the files to put into it, so we combine the -c and -f options:

C:\ jar -cf GraphLayout.jar *.class audio

This operation is completed in stony silence. If that makes you nervous, you can get some more feedback by adding the -v option (verbose). Like -f, the -v option can be combined with most of jar’s other options: ...

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.