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:

  1. Press the key
  2. Type “advanced system” immediately after pressing the key
  3. Click on View advanced system settings under the Best match heading
Windows 10 Start Menu
Windows 10 Start Menu
  1. Select Environment Variables
  2. In the System variables section, click on the New... button
  3. Enter “CLASSPATH” for the Variable Name
  4. Enter the desired path
Windows 10 Environment Variables
Windows 10 Environment Variables

Be sure to put the semicolon at the end of the line.  I have run into problems caused by a missing semicolon.

  1. Click on OK
  2. 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).


Leave a Reply

Your email address will not be published. Required fields are marked *