CLASSPATH is actually an environment variable in Java, and tells Java applications and the Java Virtual Machine (JVM) where to find the libraries of classes. These include any that you have developed on your own. An environment variable is a global system variable, accessible by the computer's operating system (e.g., Windows). Other variables include COMPUTERNAME and USERNAME. In Java, CLASSPATH holds the list of Java class file directories and the JAR file, which is Java's delivered class library file.
To set CLASSPATH, there are two ways you can follow
1. Using Command Prompt
2. Using System Settings ( for windows only )
USING COMMAND PROMPT :
Command to set CLASSPATH in windows :
If there is no CLASSPATH already existing then we can use below command.
SET CLASSPATH=.;C:\Program Files\Java\jdk1.7.0_75\lib
A thing to be aware of is we need to have a ‘.;’ before our actual path to denote the current directory.
If a CLASSPATH entry already exist then we can use the command below,
SET CLASSPATH=%CLASSPATH%;C:\Program Files\Java\JDK1.6.20\lib
Command to set CLASSPATH in Unix/Linux
export CLASSPATH="classpath"
Now, either .bash_profile or .bashrc script can be used which will run whenever you login into your Linux or Unix Machine. To check the value of classpath, echo command can be used.
USING SYSTEM SETTINGS :
To set Classpath,
1. Go to system properties ( search properties in your machine, using the start key [the left bottom most option on your desktop])
2. Select Advance Settings.
3. Choose environment variables and search for System Variables tab.
4. In System variables, Click Classpath and edit.
5. If Classpath doesn't exist, then select new.( You will have to specify the variable name in this case, to denote current directory use dot (.))
6. Add all folders separated with separator.
7. Click OK.