Set Classpath Java

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:

Example:

  • Set classpath for┬ájar file:

2015-01-12 10_04_56-C__WINNT_system32_cmd.exe

  • Set classpath for zip file:

2015-01-12 10_07_16-C__WINNT_system32_cmd.exe

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

Leave a Reply

Your email address will not be published. Required fields are marked *