2 Minutes To Code (β Version)

'java' command - 2 minute tutorial

How to set classpath

Before using any java class or other resources (jars, properties file, xml file etc), you need to add them to the classpath using the option -cp or -classpath of the java comamnd.

If you give a folder name as value of the classpath option, then all java classes contained in this folder will be included in classpath by java. Additionally, all properties file, xml file ect will also be included in classpath. In the example below, the contents of folder binaries is added to classpath.

However, any jar file will not get included. They have to be included by specifying the complete path of the jar file.

As shown in the next example, any class inside sub-folders that reflect its package hierarchy will also be included in classpath.