What exactly is a class path in java?

CLASSPATH is an environment variable that helps us to educate the Java Virtual Machine from where it will start searching for .class files.

We should store the root of the package hierarchies in the CLASSPATH environment variables.

In case of adding or using jar libraries in our project, we should put the location of the jar file in the CLASSPATH environment variable.

Example: If we are using jdbc mysql jar file in our java project, We have to update the location of the mysql jar file in the CLASSPATH environment variable. if our mysql.jar is in c:\driver\mysql.jar then

We can set the classpath through DOS in Windows

set CLASSPATH=%CLASSPATH%;c:\driver\mysql.jar 

In Linux we can do

export CLASSPATH=$CLASSPATH:[path of the jar]

Hope it helps!

Leave a Comment