How to Set classpath to Import JAR Files
Let’s see how to set classpath and why there is a need to set the classpath.
The classpath is the path that the Java runtime environment searches for classes and other resource files. It tells JDK tools and applications where to find “third-party and user-defined classes” i.e classes that are not Java extensions or part of the Java platform.
Suppose you are working on a java project “using notepad or without using any IDE” than to make the additional necessary jar files available to your project, you need to set each jar file by giving full path of the jar file in the classpath.
You can define your all the jar file once and no need to give classpath every time you start command prompt, this can be done as follows:
- Right click on my computer —> properties —> advanced system settings —> Environment variables —> Click on “New” below user variables.
- Enter Variable name as classpath
- Enter Variable value as specify complete path like “
- click on ok button
- Now you will see a new variable with name classpath and in value the specified path of jar file with name
- If you want to add another jar, for this click edit —> add semicolon <“;“> then the path of other jars, like
This way you can set the classpath.