I want to easily switch between different java versions and therefore want to set home path and path at system level in enviroment variables by running a bat/cmd file.
My .bat file looks like this:
@echo off
echo Setting JAVA_HOME
set JAVA_HOME=C:\Program Files\Java\jdk1.8.0
echo JAVA_HOME: %JAVA_HOME%
echo setting PATH
set PATH=%JAVA_HOME%\bin;%PATH%
echo PATH: %PATH%
If i type echo %JAVA_HOME% in same commandprompt then it prints the path to jdk1.8.0 but not if i open up a new commandprompt, also if i look in enviroment variables it is not listed there.
EDIT: I've also tried
@echo off
echo Setting JAVA_HOME
setx JAVA_HOME "C:\Program Files\Java\jdk1.8.0"
echo JAVA_HOME: %JAVA_HOME%
echo setting PATH
setx PATH "%JAVA_HOME%\bin;%PATH%"
echo PATH: %PATH%
echo Display java version
java -version
And this works, at the user level, but not at the system level.