The Class Path
The concept of a
path
should be familiar to
anyone who has worked on a DOS or Unix
platform. It’s an environment variable that provides an
application with a list of places to look for some resource. The most
common example is a path for executable programs. In a
Unix shell, the
PATH environment variable is a colon-separated
list of directories that are searched, in order, when the user types
the name of a command. The Java CLASSPATH
environment variable, similarly, is a list of locations that can be
searched for packages containing Java class files. Both the Java
interpreter and the Java compiler use CLASSPATH
when searching for packages and classes on the local host.
A location on the class path can be a
directory name or the name of a class archive
file. Java supports archives of class files in its own
Java archive ( JAR) format, and in the conventional
ZIP
format. JAR and ZIP are really the same format, but JAR archives
include extra files that describe each archive’s contents. JAR
files are created with the SDK’s
jar utility; many
tools for creating ZIP archives are publicly available. The archive
format enables large groups of classes to be distributed in a single
file; the Java interpreter automatically extracts individual class
files from an archive, as needed.
The precise means and format for setting the class path vary from
system to system. On a
Unix system, you set the
CLASSPATH environment variable with a colon-separated list of directories and class ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access