Java Reference
In-Depth Information
$ jar cmf manifest payback.jar net
$ ls -la
total 20
drwxrwxr-x 3 mschwarz mschwarz 4096 Aug 4 18:19 .
drwxrwxr-x 7 mschwarz mschwarz 4096 Aug 4 17:57 ..
-rw-rw-r-- 1 mschwarz mschwarz 43 Aug 4 18:17 manifest
drwxrwxr-x 3 mschwarz mschwarz 4096 Jul 28 16:16 net
-rw-rw-r-- 1 mschwarz mschwarz 7506 Aug 4 18:21 payback.jar
The options to
jar
tell it what to do. In our case,
-c
instructs to create a
JAR file,
-m
adds the contents of the file named in the next parameter to the
META-INF/MANIFEST
file,
-f
and the next parameter is the filename of the JAR
file being created. If we had not specified
-f
, the JAR file would have been
written to standard
out
and an I/O redirect would be needed, but the result
would have been the same:
$ jar cvm manifest net > payback.jar
$ ls -la
total 24
drwxrwxr-x 3 mschwarz mschwarz 4096 Aug 4 18:24 .
drwxrwxr-x 7 mschwarz mschwarz 4096 Aug 4 17:57 ..
-rw-rw-r-- 1 mschwarz mschwarz 43 Aug 4 18:17 manifest
drwxrwxr-x 3 mschwarz mschwarz 4096 Jul 28 16:16 net
-rw-rw-r-- 1 mschwarz mschwarz 7506 Aug 4 18:27 payback.jar
Everything that follows parameters required by option letters is considered
to be a file or directory that is to be added to the JAR file. The option syntax
for
jar
is similar to that for
pkzip
in the DOS/Windows world and the
tar
utility in the UNIX world.
As elsewhere in this chapter, we are just getting you started. See Sun's
documentation for details.
5.11.2
We have already covered the most common case, using
jar
to create a “rolled-
up” Java application.
jar
has many command options besides
-c
and we'll
document a few of them.
Basic jar Operation
-c
Create a JAR file.
-u
Update a JAR file—replace updated files, add missing files.