The Extension Mechanism
The Extension Mechanism
The extension mechanism provides a standard, scalable way to make custom APIs available to all applications running on the Java platform. Java extensions are also referred to as optional packages
Extensions are groups of packages and classes that augment the Java platform through the extension mechanism. The extension mechanism enables the runtime environment to find and load extension classes without the extension classes having to be named on the class path. In that respect, extension classes are similar to the Java platform’s core classes. That’s also where extensions get their name – they, in effect, extend the platform’s core API.
Since this mechanism extends the platform’s core API, its use should be judiciously applied. Most commonly it is used for well standarized interfaces such as those defined by the Java Community Process, although it may also be appropriate for site wide interfaces.
The JRE consists of those directories within the highlighted box in the diagram. Whether your JRE is stand-alone or part of the JDK software, any JAR file in the lib/ext of the JRE directory is automatically treated by the runtime environment as an extension.
Since installed extensions extend the platform’s core API, use them judiciously. They are rarely appropriate for interfaces used by a single, or small set of applications.
Furthermore, since the symbols defined by installed extensions will be visible in all Java processes, care should be taken to ensure that all visible symbols follow the appropriate “reverse domain name” and “class hierarchy” conventions. For example, com.mycompany.MyClass.
As of Java 6, extension JAR files may also be placed in a location that is independent of any particular JRE, so that extensions can be shared by all JREs that are installed on a system. Prior to Java 6, the value of java.ext.dirs referred to a single directory, but as of Java 6 it is a list of directories (like CLASSPATH) that specifies the locations in which extensions are searched for. The first element of the path is always the lib/ext directory of the JRE. The second element is a directory outside of the JRE. This other location allows extension JAR files to be installed once and used by several JREs installed on that system. The location varies depending on the operating system:
- Solaris™ Operating System: /usr/jdk/packages/lib/ext
- Linux: /usr/java/packages/lib/ext
- Microsoft Windows: %SystemRoot%\Sun\Java\lib\ext
install the extension