I'm working in a Windows XP environment and have recently installed java 1.6 because it was required by an application.

However I don't want this to be the default version of java to be used. How do I set it so that the command java -version will return 1.5.x

link|improve this question
I would take a look at path environment variable. You can examine it in command line with: echo %PATH%. These are default folders where binaries are looked for. If you find a path to JAVA you could adjust it easily in System Preferences. – Rekin Mar 24 '11 at 15:08
feedback

migrated from stackoverflow.com Mar 26 '11 at 14:55

This question came from our site for professional and enthusiast programmers.

4 Answers

up vote 2 down vote accepted

Change your PATH variable so that it has the location of the jdk5/bin directory:

  1. Start -> Control Panel -> System -> Advanced
  2. Click on Environment Variables, under System Variables, find PATH, and click on it.
  3. In the Edit windows, modify PATH by adding the location of your jdk5/bin directory to the beginning. If you do not have the item PATH, you may select to add a new variable and add PATH as the name and the location of the directory as the value.
  4. Close the window.
  5. Reopen Command prompt window, and run java -version
link|improve this answer
That didn't work. The jre bin wasn't previously part of the path so it must be set somewhere else. – Dunc Mar 24 '11 at 15:14
1  
That's because when you install Java, the bins are put into C:\WINDOWS\system32, which is part of your PATH. You should add the jre/bin directory to the beginning of the PATH. – dogbane Mar 24 '11 at 15:17
Sorry didn't spot the beginning part. Thanks – Dunc Mar 24 '11 at 15:25
feedback

In the command shell:

set JAVA_HOME=C:\jdk1.6.0u24
set PATH=%JAVA_HOME%\bin;%PATH%

That will temporarily set up the environment in the command shell. Maven, Ant, etc. will pick up on your new version of Java without having to go to the Control Panel repeatedly.

Tools like Eclipse should be able to select which JDK to use in their own configuration tools for use within their environments.

link|improve this answer
feedback

There are two ways to fix this:

1) Change the PATH (as someone has already mentioned) The important thing with this solution is to set JAVA_HOME before the windows paths. This is because under the windows folder, there is a java.exe that redirects to the last installed jre.

2) Regedit. The key HKEY_LOCAL_MACHINE->SOFTWARE->JAVASOFT->Java Runtime Environment contains the last installed version that the java.exe in the windows folder redirects to. If you change this to a previously installed version, everything should be peachy. (At least, I think this is the right registry key)

link|improve this answer
feedback

The latest version of JRE that you have always takes precedence over any PATH setting. So, to be sure, uninstall the 1.6 JRE if you don't want it to be the main one. You can have any number of JDKs installed in parallel.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.