This is a bit of a pain on Windows. Here's what I do.
Install latest Sun JDK, e.g. 6u11, in path like c:\install\jdk\sun\6u11
, then let the installer install public JRE in the default place (c:\program files\blah
). This will setup your default JRE for the majority of things.
Install older JDKs as necessary, like 5u18 in c:\install\jdk\sun\5u18
, but don't install the public JREs.
When in development, I have a little batch file that I use to setup a command prompt for each JDK version. Essentially just set JAVA_HOME=c:\jdk\sun\JDK_DESIRED
and then set PATH=%JAVA_HOME%\bin;%PATH%
. This will put the desired JDK first in the path and any secondary tools like Ant or Maven can use the JAVA_HOME
variable.
The path is important because most public JRE installs put a linked executable at c:\WINDOWS\System32\java.exe
, which usually overrides most other settings.