In addition to the Java 2 platform's many changes and enhancements at the
programming level, there have also been significant changes made in terms
of tools, set-up, and system configuration. This article details many
of these diverse changes and offers a historical perspective.
Execution and Configuration
First, the jre command has been eliminated. This was once an
alternative to using java as a means of starting a Java
program. The jre command was part of the Java Runtime
Environment, but with the Java 2 platform, the runtime and development
environments have effectively merged.
Also, the classes.zip file has been eliminated, and the
associated use of the classpath has significantly changed.
Classpath Background
With JDK 1.1, the default classpath value indicated the path where the Java
system classes resided (classes.zip), along with the current
working directory ("."). Either the -classpath
flag, or the CLASSPATH environment variable could be used to
add a new library location to the classpath, to expand upon the core set of
libraries provided for by the JDK.
If the CLASSPATH environment variable was set, the effective
classpath would still contain the classes.zip file (as in the
default setting), but with the newly assigned value in place of the current
working directory.
If, on the other hand, the -classpath option was used, the
<path> values had to explicitly contain both the original
classes.zip reference, and the new application classes:
C:> java -classpath
C:\jdk-path\lib\classes.zip;\app\classes Application
This discrepancy between the two means of setting the classpath caused a
great deal of confusion--along with outright errors. Often, the explicitly
specified version of classes.zip did not match the version of
the java command being used.
Thankfully, this anomaly has been rectified with the Java 2 platform. The
-classpath option now has the same functionality as the
CLASSPATH environment variable. But the single search path
once specified by the classpath, has been broken down into three distinct
areas--which will be discussed in the following sections.
New Class Search Paths
With the Java 2 platform, the system classes no longer reside in a zip file
(a good idea, considering occasional misguided attempts at unzipping the
file). They're now stored in a Java Archive (jar) file. The runtime
classes are found in the file rt.jar (located in the
jre/lib directory), while the JDK-supported tool classes are
found in the tools.jar file (located in the lib
directory).
Also, the system class files are no longer specified by either
CLASSPATH or -classpath. Instead, the location
is specified automatically by the runtime environment (see
sun.boot.class.path property). This default can be changed
with the Xbootclasspath compile time flag:
-Xbootclasspath:paths/files. But it's important to remember
when using this flag to also include the default rt.jar file.
With the Java 2 platform, the only classes trusted by the runtime, are
those in the boot classpath. Thus, by explicitly adding something to the
system classpath it becomes trusted. With the old JDK 1.1, anything loaded
locally from classpath became trusted.
Two other jar files ship with the Java 2 platform--the
il8n.jar, which provides internationalization support classes
(similar to the java.text.resources subpackage), and the
jaws.jar file, which provide capabilities such as JavaScript
integration with Netscape's JSObject, along with
JSException classes, and browser plug-in interoperability.
Both the il8n.jar and jaws.jar files are found in
the jre/lib directory.
Extensions Framework
While CLASSPATH or -classpath can still be used
to add nonsystem libraries, this process, too, has been greatly simplified
with the Java 2 platform. Simply place a jar file in the
lib/ext directory, under the Java runtime directory
(jre/lib/ext with the JRE), and the library is added. The
lib/ext directory is included in the system policy file, and
is given all permissions.
For those classes not contained in a jar file, they can be added simply by
placing them in the classes directory--also found under the
Java runtime directory (jre/classes). Note, however, that
this directory does not exist by default.
Any native libraries that are installed with an extension are stored in the
following directories:
Solaris: $JAVA_HOME.lib/<arch>
(sparc, intel, etc.)
Windows: $JAVA_HOME/bin
The new Extensions Framework also directs its attention to downloadable
extensions. To use a library within an applet, the library file can be
specified in a special Class-Path: line in the manifest file
of the applet's jar file. This is a handy alternative to either storing
everything in one very large jar file, or specifying multiple jar files
within the <APPLET> tag (both of which can still be
done).
Below is a sample Class-Path manifest file entry--adding jar
files to the normal classpath as extensions:
Class-Path: someJar.jar stuff/more.jar
Once the extension is found, it is downloaded and placed into a namespace
in memory. Such downloaded extensions are purely temporary, however.
Also, they cannot use native code, and must be signed or loaded from a
trusted source to gain permission to perform system-level actions.
Search Paths Summary
In summary, three basic search paths are now used to find classes:
(The properties below can only be examined from a trusted program.)
- The first location searched is the boot classpath.
This can be set using the
-Xbootclasspath
option, and can be examined by calling
System.getProperty("sun.boot.class.path").
- The second location searched is the extension directories
(
jre/lib/ext). The list of directories can be
examined by calling System.getProperty("java.ext.dirs").
- The third and final location searched is the application classpath,
set by either
-classpath or CLASSPATH.
The value of this path can be examined by calling
System.getProperty("java.class.path").