Setting the CLASSPATH Variable in Windows 10
September 11, 2018 by Michael
If you’re using the Java compiler from the command line or some other tooling that depends on the Java compiler, you may be asked to setup the CLASSPATH
variable. If you’re coming from a .NET background, odds are you haven’t had to deal with this before.
Note, you do not always need to modify the CLASSPATH variable. As an alternative you can simply pass the path of the JAR file to java using the -cp command line argument. You can find more about that here.
Follow the steps below to add the CLASSPATH
variable to your Windows 10 environment variables:
- Press the
key
- Type “advanced system” immediately after pressing the
key
- Click on
View advanced system settings
under theBest match
heading
- Select
Environment Variables
- In the
System variables
section, click on theNew...
button - Enter “CLASSPATH” for the
Variable Name
- Enter the desired path
Be sure to put the semicolon at the end of the line. I have run into problems caused by a missing semicolon.
- Click on
OK
- You may need to close and reopen any terminal or Command Prompt you currently have open.
Your CLASSPATH
environment variable should now be set. Hopefully this resolves the error you were dealing with. If you continue to get an error message, be sure you have a ;
at the end of the line. Should you need to add an additional directory to the CLASSPATH
variable simply add it after the semicolon (as you would the PATH
environment variable).