Set Classpath Java
Set Classpath is necessary if you run java program which is dependent on other classes. Java runtime environment search for resources and classes to run the code and if it’s not found you get class not found exception. Classpath generally set for *.zip, *.jar or *.class files.
Synopsis:
C:> set CLASSPATH=classpath1;classpath2;classpath3;
Example:
- Set classpath for jar file:
- Set classpath for zip file:
To set class files classpath there could be two types of scenario.
- If class file belong from unnamed package. In this case set class path to the directory which contain the class file
- If class file belongs to named package then set class path to the directory of the root package i.e. first package with full package name
Note: If you have multiple entries for classpath then its should be seperated by semi-colon and its important to remove any spaces from around equals sign.
- For more details please refer oracle documentation here