O'Reilly logo

Mac OS X for Java Geeks by Will Iverson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

JAR Files

Virtually all delivery mechanisms for Java applications depend on packaging the .class files created from your .java source files into one or more Java Archive (JAR) files. Think of a JAR file as a special sort of ZIP archive, with a very specific set of expected characteristics and layout. You can use the jar tool included with the JDK, an Ant task, or the specific capabilities of your preferred Java development environment to create a JAR file.

The standard way to create a JAR file, of course, is to use the command-line jar command included with Mac OS X’s JDK. Open the Terminal, type jar, and a list of options will appear:

Usage: jar {ctxu}[vfm0M] [jar-file] [manifest-file] [-C dir] files ... Options: -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 output -f specify archive file name -m include manifest information from specified manifest file -0 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 If any file is a directory then it is processed recursively. The manifest file name and the archive file name needs to be specified in the same order the 'm' and 'f' flags are specified. Example 1: to archive two class files into an archive called classes.jar: jar cvf classes.jar Foo.class Bar.class ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required