How to Set Classpath Using Environment Variables for Jar Files in Java?
Share
Description for Setting Classpath Using Environment Variables for Jar Files in Java
Description: Whenever a Java application executes, it checks for Java classes in the *CLASSPATH* to execute without errors. The *CLASSPATH* commonly contains paths to JAR files, with the OS path separator being `;` in Windows. To specify the classpath while running a program using the command line, you can use the command `java -cp "some.jar;someOther.jar" com.edureka.HelloWorld`. These two JAR files will be available to the program currently executed. If these JARs are set in the *CLASSPATH* environment variable, they will be available to all programs. Additionally, the wildcard `*` can be used to include all JAR files inside a folder.
Screenshots
STEP 1: Open Advanced System Settings. In Windows 10, press *Windows Key + Pause Key*, which will open the System settings window. Then, navigate to *Change settings* and select the *Advanced* tab. Alternatively, press the *Windows Key*, click the search box, and type 'advanced system settings'.
STEP 2: Click the option that says *View advanced system settings*.
STEP 3: Set the *JAVA_HOME* Environment variable. After clicking on *System Settings*, the box below will appear. Navigate to the *Advanced* tab and click the *Environment Variables* button.
STEP 4: Click the "New" button under *System variables*, and enter *JAVA_HOME* as the "Variable name", and the path to your Java JDK directory under "Variable value".
STEP 5: Update the System PATH variable. Follow these steps:
Click on *Path* under *System Variables*.
Click *Edit*.
In the *Edit environment variable* window, click *New*.