Java

Extensions - An Overview

Contents

What an extension is

Extensions are packages of Java classes (and any associated native code) that application developers can use to extend the functionality of the core platform. The extension mechanism allows the Java virtual machine (VM) to use the extension classes in much the same way as the VM uses the system classes. (System classes are those comprising the core API of the Java platform, located in lib/classes.zip in the JDK or in lib/rt.jar in the JRE.) The extension mechanism also provides a way for needed extensions to be retrieved from specified URLs when they are not already installed in the JDK or JRE.

Extensions are embodied in JAR files. Every JAR file is a potential extension. A JAR file can be made to play the role of an extension in two ways:

When the VM is searching for a class of a particular name, it will first look among the system classes. If it fails to find the desired class there, it will next look for the class among any installed extensions. If it doesn't find the class among either the system classes or the installed extensions, the VM will search among any download extensions referenced by the application or applet.

Installed extensions

Installed extensions are JAR files in the directory
<java-home>/lib/ext
where <java-home> is the top-level directoy of the JDK or JRE. Classes within JAR files in this directory can be used by applets and applications much as if they were part of the set of system classes, without having to explicitly include them in the classpath.

An installed extension's native code binaries, if any, are placed in

<java-home>\bin         [Win32]
<java-home>/lib/<arch>  [Solaris]
where <arch> is the Solaris processor architecture, either sparc or x86.

When the Java VM encounters a class name, it looks first for the class in the set of system classes. If it fails to find the desired class among the system classes, the VM will then search for the class in any JAR files in <java-home>/lib/ext.

Note that there is nothing special about any particular JAR file itself or the classes it contains that makes it an installed extension. It is an installed extension by virtue of its location in <java-home>/lib/ext.

If a class is not found after searching both the system classes and the classes in the installed extensions, the extension mechanism will search for the class in a download extension....

Download extensions

Download extensions are JAR files that are referenced by the manifest files of other JAR files. In a typical situation, an applet will be bundled in a JAR file whose manifest references a JAR file (or several JAR files) that will serve as an extension for the purposes of that applet. Extensions may reference each other in the same way.

Download extensions are specified in the "Class-Path" header field in the manifest file of an applet, application, or another extension. A Class-Path header might look like this, for example:

Class-Path: servlet.jar infobus.jar acme/beans.jar
With this header field, the classes in the files servlet.jar, infobus.jar, and acme/beans.jar will serve as extensions for purposes of the applet or application. The URLs in the Class-Path field are given relative to the URL of the JAR file of the applet or application.

Unlike the case of installed extensions, the location of the JAR files that serve as download extensions is irrelevent. A download extension is an extension because it is referenced from the Class-Path header in another JAR file's manifest, not because it has any particular location.

Another difference between installed and download extensions is that only applets and applications bundled in a JAR file can make use of download extensions. Applets and applications not bundled in a JAR file don't have a manifest from which to reference download extensions.

When searching for a class, the VM first searches among the classes in the system classes and in any installed extensions. If the class is not found in either the system classes or in the installed extensions, the VM will search for the class in any download extensions referenced by the manifest of the application or applet. A download extension will not be downloaded if a desired class is found among the installed extensions, even if the download extension is referenced by the manifest file of the applet or application.

The extension mechanism will not install a download extension in the JRE or JDK directory structure. Download extensions do not become installed extentions after they have once been downloaded.

Unlike installed extensions, download extensions cannot have any native code.


Copyright © 1997 Sun Microsystems, Inc. All Rights Reserved.

Please send comments to: Java Software
Sun

Java Software
Last modified: Fri Dec 5 15:19:44 PST