'C:\Program' is not recognized error

Yet another solution is to do this: C:\Program Files has a short name

C:\Progra~1

in windows.

so simply write Progra~1 instead of the Program Files. {added missing 'r'}


Okay, that makes it clearer.

There are two main problems here.

First of all, the reason you're getting 'C:\Program' is not recognized... is, of course, because it contains spaces. The fact that you have it quoted in the PATH environment variable has no relation to how %JAVA_HOME% is interpreted at the prompt. You have two options.

  1. Quote it when you define the variable, i.e. set JAVA_HOME to "C:\Program Files\Java\jdk1.7.0_25"
  2. Quote it when you invoke it. Type "%JAVA_HOME%\bin" at the prompt. Of course, you'll get the "not recognized as an internal or external command, operable program or batch file" error unless you end the path with an executable (e.g. "%JAVA_HOME%\bin\javac.exe"), but you'll see that this way it complains about '"C:\Program Files\Java\jdk1.7.0_25"' rather than 'C:\Program'.

Second, you can't use environment variables in the path. You can use environment variables when you set the path at the command prompt. For example,

set PATH=%PATH%;%JAVA_HOME%

will work, but that's because %JAVA_HOME% is expanded at the command line and PATH is set to the result. If you check the value of PATH, you'll see that it ends with C:\Program Files\Java\jdk1.7.0_25, not %JAVA_HOME%.

Also, if javac.exe is in the bin subdirectory, you'll need to include that in the path, i.e. add ;C:\Program Files\Java\jdk1.7.0_25\bin to the path.

(BTW, you have %JAVA_HOME% in the path twice, and there's an extra semicolon after the second one.)


Even though Adi Inbar is pretty clear on the problem, I think his workaround isn't the best solution, because it tries to patch around the original problem: spaces in the path of your JDK installation.

The best way to solve your problem is actually reinstalling JDK to a space-less path. All other workarounds will cause you headaches in the long run.


Is the path you are setting the JAVA_HOME environment variable in a user variable or a system variable? You cannot use user variables within system variables. So if JAVA_HOME is defined as a user variable and you are adding it to your system path that won't work.

From the output of your set command it looks like %JAVA_HOME% is not being resolved. It should show the expanded version not the one with % signs in.

Add a Path user variable and add %JAVA_HOME%\bin to that. Windows will add your user path to the end of the system path.

You should not need quotes in the JAVA_HOME variable even if it contains spaces.