O'Reilly logo

Java Cookbook by Ian F. Darwin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using Extensions or Other Packaged APIs

Problem

You have a JAR file of classes you want to use.

Solution

On JDK 1.2 or later, simply copy the JAR into JDKHOME/jre/lib/ext/.

Discussion

The Java API has grown by leaps and bounds since its first public release in 1995. It is now considered sufficiently functional for writing robust applications, but the areas to which it is being applied continue to grow. There are many specialized APIs that may require more resources than you have on a given Java platform. Many of the new APIs from Sun are in the form of standard extensions and have package names beginning in javax. to indicate that. Classes in packages named java. or javax. are treated as built-in classes by a web browser for purposes of applet security, for example. Each extension is distributed in the form of a JAR file (see Section 23.4).

If you have Java 1.1 or some clone, you will need to add each such JAR file to your CLASSPATH, as in Section 2.6.

In Java 2, as you accumulate these and other optional APIs contained in JAR files, you can simply drop these JAR files into the Java Extensions Mechanism directory, typically something like \jdk1.2\jre\lib\ext., instead of listing each JAR file in your CLASSPATH variable and watching CLASSPATH grow and grow and grow. Effective with Java 2, the runtime looks here for any and all JAR and zip files, so no special action is needed. In fact, unlike many other system changes, you do not even need to reboot your computer, since this directory ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required