Script to change the JAVA_HOME system variable on Windows

I do most of my work against JDK 1.5, but sometimes I have to change to 1.6. it hurts a bit when I have to manually switch to my JAVA_HOME system variable, when I need to work on a specific project for one or the other (and no, Eclipse does not play well in these scenarios - believe me ... I tried.)

I am looking for a registry registry or a Windows script shell or, for that matter, any means by which I can "switch" this system variable to something that is easy to run.

I mixed up the 'set' command, but that only sets the variable for this particular instance of the command - not globally.

Thanks in advance.

EDIT No. 1: Recommendations:

  • Use the JAVA_HOME variable in the path variable, so all you have to do is change JAVA_HOME (which is used in many projects anyway [maven, ant, etc])
  • Write the command in several batch scripts for convenient use.
  • When you make changes, the Windows command session will not immediately reflect it. You must close and reopen it.
+7
java scripting path
source share
1 answer

You can use setx for this purpose.

Same:

 setx /M JAVA_HOME "C:\Program Files (x86)\Java\jdk1.6.0_17" 
+16
source share

All Articles