JAR Files
Java Archive (JAR) files are Java’s suitcases. They are the standard and portable way to pack up all the parts of your Java application into a compact bundle for distribution or installation. You can put whatever you want into a JAR file: Java class files, serialized objects, data files, images, audio, etc. A JAR file can also carry one or more digital signatures that attest to its integrity and authenticity. A signature can be attached to the file as a whole or to individual items in the file.
The Java runtime system can load class files directly from an
archive in your CLASSPATH, as described
earlier. Nonclass files (data, images, etc.) contained in your JAR file
can also be retrieved from the classpath by your application using the
getResource() method
(described in Chapter 12). Using this facility,
your code doesn’t have to know whether any resource is in a plain file or
a member of a JAR archive. Whether a given class or data file is an item
in a JAR file or an individual file on the classpath, you can always refer
to it in a standard way and let Java’s class loader resolve the
location.
File Compression
Items stored in JAR files are compressed with the standard ZIP file compression. Compression makes downloading classes over a network much faster. A quick survey of the standard Java distribution shows that a typical class file shrinks by about 40 percent when it is compressed. Text files such as HTML or ASCII containing English words often compress to one-tenth their ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access