Different ways to specify the classpath
suggest changeThere are three ways to set the classpath.
- It can be set using the
CLASSPATH
environment 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 -classpath
(or -cp
) option takes precedence over the CLASSPATH
environment variable.
- The classpath for an executable JAR file is specified using the
Class-Path
element inMANIFEST.MF
:
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 Class-Path
element.
If no classpath is specified, then the default classpath is the selected JAR file when using java -jar
, or the current directory otherwise.
Related:
- https://docs.oracle.com/javase/tutorial/deployment/jar/downman.html
- http://docs.oracle.com/javase/7/docs/technotes/tools/windows/classpath.html
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents