Using JAR Files

   

Using JAR Files

Java introduced Java Archive files ( JAR files) back in JDK 1.1. JAR files bundle multiple files into a single deployable archive file that can be used in Java applications and/or applets. JAR files provide many valuable features for Java applications. Some of the features are

  • Bundling

  • Compression

  • Portability

  • Versioning

  • Security

  • Decreased Download Time

Each of these features is described in more detail in the following sections.

Bundling

A complex applet or application might consist of dozens or hundreds of Java classes, each stored in a separate class file (recall that each public class must be stored in a separate file). For applets, the Web browser makes an HTTP connection to load each file, as needed, from the server. Establishing an HTTP connection entails overhead, and if the class files are small, as they typically are, much of the time spent loading an applet can be spent establishing the multiple HTTP connections required to load all the class files.For

For Java applications, bundling aids in application distribution. Because there can be many class files and/or resources within a single JAR file, an entire application can be contained exclusively within a JAR. If you need to redistribute a newer version of your software, just install the new JAR file over the older version

Note

JAR files can contain any type of file, class files, images, HTML pages, and even other JAR files.


Compression

JAR files, like CAB files, are compressed. For example, using the TicTacToe directory located in the JAVA_HOME/demo/applets directory is about 40.2KB in a standard SDK 1.3 installation. If you JAR the entire contents of that directory, the JAR file is approximately 29KB. That's about a 28% compression rate. Not bad, but it's obviously dependent on the type of the files. Usually, graphics are already compressed, so their compression is not so hot. The point is that it compresses files and resources and can greatly reduce the size of the distri bution.

Portability

The JAR file utilities are part of Java's core API. As long as there is a current version of Java for that platform, JAR files will port to that platform.

Versioning

Since JDK 1.2, JAR files have had the capability to contain meta-information about the contents of the JAR itself. This meta-data is stored in a file called MANIFEST.MF. This file has to be in a directory within the JAR file called META-INF. (Notice, the name of the file and directory are uppercase.)

By using the manifest file, a JAR file can record information about what files are in the JAR, what version each file is, who the vendor was, and so on. You'll hear more about the manifest file shortly.

Security

JAR files can be signed digitally so that users can download them as trusted pieces of an application. This is very important for applications or applets that are downloaded over the Web. It's also important for users who don't allow code to execute if they don't know where it came from.

Decreased Download Time

Because a single JAR file can contain multiple files and be compressed, their download times are reduced dramatically.

   


Special Edition Using Java 2 Standard Edition
Special Edition Using Java 2, Standard Edition (Special Edition Using...)
ISBN: 0789724685
EAN: 2147483647
Year: 1999
Pages: 353

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net