Set Classpath in Java Permanently

Setting classpath is the most essential part that every Java starter has to know because not just Java gives the developer the capability to do any thing instead it is the frameworks. We'll have to know first How-To use frameworks and setting the classpath is a part of it.


The name itself says, path of the class(es) which are to be used in a program. We usually write the import statement but what does it really mean? It means that we're using the classes in a particular package or simply the class. When compiling, the java compiler (javac) has to know where those class files reside in order to complete the compilation successfully. The javac usually knows it, it searches for rt.jar file in the lib directory of your JRE installation.

All the class files are packed in a jar file i.e. a file with .jar extension. So when you need to access classes in the jar file you must add those package to import and for this statement to compile, the jar file's location must be known to the compiler.

The Best way to say about a jar file to the compiler is creating an environmental variable named CLASSPATH from the Advanced Settings window of your Windows PC.

However, there is also an alternate way of setting the classpath temporarily using set path="some_path", however as the name itself says you'll have to set it every time when you make use of it. This is again a big head ache.

Describing the process of setting the classpath does not sound good, instead a video representation would be much more clear so i had done it my PC and then uploaded it for you.


Posted by at on

Tags: Software Installation,