SET JAVA_HOME in windows bat file not working

user955732 picture user955732 · Nov 26, 2013 · Viewed 50.6k times · Source

why is SET JAVA_HOME in this bat file not overriding the environment variable JAVA_HOME?

someFile.bat

@ECHO OFF
SET JAVA_HOME = Progra~2\Java\jdk1.6.0_23
echo JAVA_HOME: %JAVA_HOME%

OUTPUT

JAVA_HOME: C:\Program Files (x86)\Java\jdk1.7.0_21

Answer

npocmaka picture npocmaka · Nov 26, 2013

because of the additional space.Try this:

echo JAVA_HOME: %JAVA_HOME %

try to set the java_home like this:

SET "JAVA_HOME=Progra~2\Java\jdk1.6.0_23"