Changing current version of Java within Windows
Solution 1:
Change your PATH variable so that it has the location of the jdk5/bin directory:
- Start -> Control Panel -> System -> Advanced
- Click on Environment Variables, under System Variables, find PATH, and click on it.
- 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.
- Close the window.
- Reopen Command prompt window, and run
java -version
Solution 2:
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.
Solution 3:
Java 8 creates three shortcuts on \ProgramData\Oracle\Java\javapath that point to the latest Java8 java.exe, javaw.exe and javaws.exe and then puts \ProgramData\Oracle\Java\javapath at the front of the PATH so that no matter what you do to the JAVA_PATH environment variable, you still get the latest Java 8.
You can get around this by
1) renaming \ProgramData\Oracle\Java\javapath to something else (\ProgramData\Oracle\Java\javapath8 for example)
2) creating a new javapath folder under Java and
3) creating the shortcuts that you need.
Just restore the javapath when you are done with the old versions and you get Java 8 back.
Solution 4:
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)