Open In App

How to Set Multiple Classpath in Java in Windows?

Improve
Improve
Like Article
Like
Save
Share
Report

In JAVA, you have to set PATH and CLASSPATH variables correctly before running any java program. After installing JDK, the next step is to set the path and CLASSPATH variables in the Windows system environment variable. CLASSPATH is an environment variable which is used by Application ClassLoader to Locate and Load the class files.

To Set the CLASSPATH there are the following ways :

A. CLASSPATH can be set permanently in the environment.

  • Click on the Windows button and choose Control Panel ⇒ Select System.

  • Click on Advanced System Settings.

  • A Dialog box will open. Click on Environment Variable.

  • If the CLASSPATH already exists in System Variables, click on the Edit button then put a semicolon (;) at the end. Paste the Path of MySQL-Connector Java.jar file.
    Else click on the New button.

  • Type Variable name as CLASSPATH and Variable value as C:\Program Files\Java\jre1.8\MySQL-Connector Java.jar;.;
    Note:  Put ;.; at the end of the CLASSPATH.

      

B. CLASSPATH can be set Using command prompt:

  • Install Latest JDK
  • Open Command Prompt and enter the command : javac -version, it shows error like below.

  • Setting path:

 set path=%path%;<java installed directory\bin>

eg: set path=%path%;C:\Program Files (x86)\Java\jdk1.7.0\bin

  • Now set classpath i.e

set classpath=%classpath%;<java installed directory\lib\*.jar>

eg: set classpath=%classpath%;C:\Program Files (x86)\Java\jdk1.7.0\lib\*.jar

  • Test javac and java commands

  • Now type java in the cmd

  • Now java is ready for you.

Last Updated : 08 Dec, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads