Different ways to specify the classpathsuggest change
There are three ways to set the classpath.
- It can be set using the
CLASSPATHenvironment variable :
set CLASSPATH=... # Windows and csh export CLASSPATH=... # Unix ksh/bash
- It can be set on the command line as follows
java -classpath ... javac -classpath ...
Note that the
-cp) option takes precedence over the
CLASSPATH environment variable.
- The classpath for an executable JAR file is specified using the
Class-Path: jar1-name jar2-name directory-name/jar3-name
Note that this only applies when the JAR file is executed like this:
java -jar some.jar ...
In this mode of execution, the
-classpath option and the CLASSPATH environment variable will be ignored, even if the JAR file has no
If no classpath is specified, then the default classpath is the selected JAR file when using
java -jar, or the current directory otherwise.