The Jar Extension Mechanism

  • May 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View The Jar Extension Mechanism as PDF for free.

More details

  • Words: 755
  • Pages: 3
The Extension Mechanism (JAR) http://java.sun.com/docs/books/tutorial/ext/basics/install.html Installed Extensions: Installed extensions are JAR files in the lib/ext directory of the Java Runtime Environment (JRE ) software. TM

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. Download Extensions Download extensions are sets of classes (and related resources) in JAR files. A JAR file's MANIFEST.MF can contain headers that refer to one or more download extensions. The extensions can be referenced in one of two ways: • •

by a Class-Path header by an Extension-List header

Note that at most one of each is allowed in a manifest. Download extensions indicated by a Class-Path header are downloaded only for the lifetime of the application that downloads them, such as a web browser. Their advantage is that nothing is installed on the client; their disadvantage is that they are downloaded each time they are needed. Download extensions that are downloaded by an Extension-List header are installed into the /lib/ext directory of the JRE that downloads them. Their advantage is that they are downloaded the first time they're needed; subsequently they can be used without downloading. But as shown later in this tutorial, they are more complex to deploy. You can list multiple URLs in a manifest. For example, the following is a valid header: Class-Path: area.jar servlet.jar images/ In the Class-Path header any URLs listed that don't end with '/' are assumed to be JAR files. URLs ending in '/' indicate directories. In the preceding example, images/ might

be a directory containing resources needed by the applet or the application.

f you need to specify more class path entries than will fit on one line, you can extend them onto subsequent continuation lines. Begin each continuation line with two spaces. For example: Class-Path: area.jar servlet.jar monitor.jar datasource.jar provider.jar gui.jar

Understanding Extension Class Loading The extension framework makes use of the class-loading delegation mechanism. When the runtime environment needs to load a new class for an application, it looks for the class in the following locations, in order: 1. Bootstrap classes: the runtime classes in JRE/lib/rt.jar, internationalization classes in i18n.jar, and others. 2. Installed extensions: classes in JAR files in the JRE/lib/ext directory of the JRE, and in the system-wide, platform-specific extension directory (such as /usr/jdk/packages/lib/ext on the Solaris Operating System, but note that use of this directory applies only to Java 6 and later). 3. The class path: classes, including classes in JAR files, on paths specified by the system property java.class.path. If a JAR file on the class path has a manifest with the Class-Path attribute, JAR files specified by the Class-Path attribute will be searched also. By default, the java.class.path property's value is ., the current directory. You can change the value by using the -classpath or -cp command-line options, or setting the CLASSPATH environment variable. The command-line options override the setting of the CLASSPATH environment variable. TM

TM

The Java Class Loading Mechanism The Java platform uses a delegation model for loading classes. The basic idea is that every class loader has a "parent" class loader. When loading a class, a class loader first "delegates" the search for the class to its parent class loader before attempting to find the class itself. Here are some highlights of the class-loading API: •



Constructors in java.lang.ClassLoader and its subclasses allow you to specify a parent when you instantiate a new class loader. If you don't explicitly specify a parent, the virtual machine's system class loader will be assigned as the default parent. The loadClass method in ClassLoader performs these tasks, in order, when called to load a class: 1. If a class has already been loaded, it returns it. 2. Otherwise, it delegates the search for the new class to the parent class loader.





3. If the parent class loader does not find the class, loadClass calls the method findClass to find and load the class. The findClass method of ClassLoader searches for the class in the current class loader if the class wasn't found by the parent class loader. You will probably want to override this method when you instantiate a class loader subclass in your application. The class java.net.URLClassLoader serves as the basic class loader for extensions and other JAR files, overriding the findClass method of java.lang.ClassLoader to search one or more specified URLs for classes and resources.

Related Documents

Mechanism
December 2019 34
Mechanism
June 2020 16
2x14 The Bean Jar
April 2020 7
Whiskey In The Jar
November 2019 10
Whiskey In The Jar
May 2020 15