Classpath is a parameter that tells applications where to look for user-defined classes. It specifies the locations for all classes that are not handled by special
class loaders. This parameter does not affect the search path for standard JRE classes.
In addition to Java applications (using the
java command), this parameter is also applicable to other JDK utilities, such as
javac,
javadoc, and others.
There are two main ways to set the classpath: through the OS environment variable
CLASSPATH, and through the command line argument
-cp (or its synonym
-classpath). The latter is preferable because it allows different values for different applications. The default value is the current directory.
The parameter includes paths to JAR files and root directories with packages. Paths are separated by
: in the command line parameter or
; in the environment variable. To include all files in a directory, the
* wildcard can be used at the end of the path.
If the application is launched as a JAR file (
java -jar), the classpath should be specified in its
manifest.