Java examples for Language Basics:Class Path
Set the CLASSPATH variable equal to the directory location of the user-defined Java classes or Java Archive (JAR) files.
set CLASSPATH=C:\JAVA_DEV\some-jar.jar
Or on Unix and Linux systems:
export CLASSPATH=/JAVA_DEV/some-jar.jar
javac command provides an option for specifying the location of resources that need to be loaded for an application.
On all platforms, setting the CLASSPATH using javac can be done via the -classpath option as follows:
javac -classpath /JAVA_DEV/some-jar.jar
on Microsoft Windows machines the file path will use the backslash (\) instead.
javac -cp option may be used, rather than specifying the -classpath option.
JVM finds and loads classes as needed using the following search order:
Following is an example of specifying multiple JAR files in the CLASSPATH environment variable on Unix and Linux systems:
export CLASSPATH=/JAVA_DEV/some-jar.jar:/JAVA_LIB/myjar.jar
Alternatively, you can specify the class path via a command-line option:
javac -classpath /JAVA_DEV/some-jar.jar:/JAVA_LIB/myjar.jar