Home

classpaths

Classpaths (or the Java classpath) are a mechanism used by the Java platform and other JVM-based environments to locate class files and libraries at runtime. A classpath is a list of file system locations and archives, such as directories and JAR or ZIP files. The runtime searches these locations in a defined order to find a requested class or resource.

The classpath can be specified in several ways: via the CLASSPATH environment variable, or via the -cp

Class loading in the JVM uses a parent-first delegation model. When a class is requested, the loader

Practical notes: avoid over-reliance on a global CLASSPATH; use -cp in scripts for reproducible builds. Quotes

(or
-classpath)
option
passed
to
the
java
launcher.
For
compilation,
javac
also
accepts
-cp.
The
current
directory
is
included
by
default
if
no
classpath
is
specified.
The
path
separator
is
a
semicolon
on
Windows
and
a
colon
on
Unix-like
systems.
Each
entry
may
point
to
a
directory
containing
package
subdirectories
or
to
a
JAR/ZIP
file;
a
JAR
may
contribute
a
manifest
Class-Path
entry
that
further
extends
the
effective
classpath.
searches
the
classpath
entries
in
order,
stopping
at
the
first
match.
Since
modern
Java
supports
modules,
there
is
also
a
module
path
for
modular
applications;
the
classpath
remains
relevant
for
legacy
and
non-modular
code.
may
be
needed
to
handle
spaces.
Common
examples
show
different
separators
for
Windows
and
Unix.
The
System.getProperty("java.class.path")
can
reveal
the
current
classpath,
and
-verbose:class
can
trace
loaded
classes.