0

On Windows 8, I've got a bat file with the following contents:

@echo off
echo Setting JAVA_HOME
set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_39
echo setting PATH
set PATH=C:\Program Files\Java\jdk1.6.0_39\bin;%PATH%
echo Display java version
java -version

which I'm trying to use to switch java versions. When I run the .bat file, it outputs the version as 1.6.0_39, but doesn't actually switch versions. Instead, I've had to manually change the path variable every time I want to use a different version. Is there something wrong with the way that I'm setting the path? When I look at the path env variable after I've run this, it doesn't look like it's changed, and you'd think that it would be fairly visible...

Current version:

@echo off
echo Setting JAVA_HOME
setx JAVA_HOME "C:\Program Files\Java\jdk1.7.0_09"
echo Display java version
java -version

with %JAVA_HOME%\bin; at the front of my path variable. Doesn't seem to be looking at %JAVA_HOME%

3
  • Use setx instead of set. Commented Feb 15, 2013 at 14:22
  • is the syntax for setx the same? I tried this and got an error: "Default option is not allowed more that '2' times" Commented Feb 15, 2013 at 14:25
  • Figured out how to get setx to work right, but now it's not finding java... I added %JAVA_HOME%\bin; to the beginning of my path, deleted the setx path from my .bat, and it doesn't seem to be using it. Commented Feb 15, 2013 at 14:33

2 Answers 2

3

The SET statement sets an environment variable for the current process only.

Set the the global (default) value of an environment variable, use setx.

Note that even setx will not affect existing processes, so you will only notice the change in a new command prompt window.

Sign up to request clarification or add additional context in comments.

Comments

0

SETX is often not supported. You can also change the registry setting. See >> this post

1 Comment

I figured out how to get setx to work, but now it can't seem to find java, even though I've got %JAVA_HOME%/bin in my path.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.