Learn to set CLASSPATH environment variable for Java in Windows OS. The steps are more or less same in all version of Windows i.e. Windows 7, Windows 8 or Windows 10.
The name of
CLASSPATH
variable is case-insensitive i.e. classpath and CLASSPATH – both can be used.
1. Steps to set classpath in Windows
- Open environment variable window. In Windows 10, we can directly search “environment variable” from taskbar search icon. In older versions, we can navigate by keyboard shortcuts:
"Windows + Pause"
–>Advanced System Settings
–>Environment Variables
- Create a new variable with name
CLASSPATH
and set the value toJAVA_HOME\lib
. Also, it is best to include current directory by including (dot or period sign).The
CLASSPATH
value is set. We can always edit its value to include or exclude more directories in it. - To verify the classpath changes, open a new command prompt and run command:
echo %CLASSPATH%
This command will show the value set for
classpath
variable.
2. Set temporary classpath from DOS prompt
To set the classpath temporarily from DOS prompt, use the command set CLASSPATH.
set CLASSPATH=.;C:/Program Files/Java/jdk1.7.0_79/lib;
The classpath variable set in this way is not persistent. The classpath will be available only in the current DOS window. It will not be available in any other window or application opened in new command prompts.
Drop me your question in comments.
Happy Learning !!
Comments