views:

159

answers:

3

How can i change the Java Runtime Version on Windows.

i installed java7 for some tests, now i need as system default the old java6, but i dont want uninstall the java7 (need it for later tests). can i change the system used jre in the control panel/java/jre tab? i can change/edit/add/delete user used version, but not the system used.

A: 

Update your environment variables

Ensure the reference to java/bin is up to date in 'Path'; This may be automatic if you have JAVA_HOME or equivalent set. If JAVA_HOME is set, simply update it to refer to the older JRE installation.

Syntax
+1  A: 

All you need to do is set the PATH environment variable in Windows to point to where your java6 bin directory is instead of the java7 directory.

Right click My Computer > Advanced System Settings > Advanced > Environmental Variables

If there is a JAVA_HOME environment variable set this to point to the correct directory as well.

David Young
+2  A: 

For Java applications, i.e. programs that are delivered (usually) as .jar files and started with java -jar xxx.jar or via a shortcut that does the same, the JRE that will be launched will be the first one found on the PATH.

If you installed a JRE or JDK, the likely places to find the .exes are below directories like C:\Program Files\JavaSoft\JRE\x.y.z. However, I've found some "out of the box" Windows installations to (also?) have copies of java.exe and javaw.exe in C:\winnt\system32 (NT and 2000) or C:\windows\system (Windows 95, 98). This is usually a pretty elderly version of Java: 1.3, maybe? You'll want to do java -version in a command window to check that you're not running some antiquated version of Java.

You can of course override the PATH setting or even do without it by explicitly stating the path to java.exe / javaw.exe in your command line or shortcut definition.


If you're running applets from the browser, or possibly also Java Web Start applications (they look like applications insofar as they have their own window, but you start them from the browser), the choice of JRE is determined by a set of registry settings:

Key: HKEY_LOCAL_MACHINE\Software\JavaSoft\Java Runtime Environment
Name: CurrentVersion
Value: (e.g.) 1.3

More registry keys are created using this scheme:

(e.g.) 
HKEY_LOCAL_MACHINE\Software\JavaSoft\Java Runtime Environment\1.3   
HKEY_LOCAL_MACHINE\Software\JavaSoft\Java Runtime Environment\1.3.1

i.e. one for the major and one including the minor version number. Each of these keys has values like these (examples shown):

JavaHome    : C:\program Files\JavaSoft\JRE\1.3.1
RuntimeLib  : C:\Program Files\JavaSoft\JRE\1.3.1\bin\hotspot\jvm.dll
MicroVersion: 1

... and your browser will look to these settings to determine which JRE to fire up.

Since Java versions are changing pretty frequently, there's now a "wizard" called the "Java Control Panel" for manually switching your browser's Java version. This works for IE, Firefox and probably others like Opera and Chrome as well: It's the 'Java' applet in Windows' System Settings app. You get to pick any one of the installed JREs. I believe that wizard fiddles with those registry entries.

If you're like me and have "uninstalled" old Java versions by simply wiping out directories, you'll find these "ghosts" among the choices too; so make sure the JRE you choose corresponds to an intact Java installation!


Some other answers are recommending setting the environment variable JAVA_HOME. This is meanwhile outdated advice. Sun came to realize, around Java 2, that this environment setting is

  1. unreliable, as users often set it incorrectly, and
  2. unnecessary, as it's easy enough for the runtime to find the Java library directories, knowing they're in a fixed path relative to the path from which java.exe or javaw.exe was launched.

There's hardly any modern Java software left that needs or respects the JAVA_HOME environment variable.


More Information:

...and some useful information on multi-version support:

Carl Smotricz