tags:

views:

94

answers:

3

I have two versions of Java setup for development. One is 1.5 and the other obviously is 1.6.

Now when I type java -version it displays up 1.6

What should I change so that it points to Java 1.5?

+5  A: 

Change the PATH variable.

set PATH=c:\java1.5\bin;%PATH%
rodrigoap
+1  A: 

On Windows:

1) set your JAVA_HOME environment variable to the 1.5 location, one level above the /bin dir, e.g. C:\myjava5dir, not C:\myjava5dir\bin

2) then set your PATH environment variable to include %JAVA_HOME%\bin

3) be sure to start a new DOS prompt to pick up the changes

Also ensure you clear any other existing references to your jdk in PATH.

Brian
`JAVA_HOME` is not actually required by any JDK itself. Some third-party applications use it (for example the Tomcat startup scripts use it), but Java itself doesn't need and/or use it at all!
Joachim Sauer
but `JAVA_HOME` is a nice way to have it put ONCE in the PATH...
Carlos Heuberger
...and is also good for updating multiple dependencies with one change when you want to flip between, say, Java versions 1.5 and 1.6. But quite right Joachim, it's not strictly essential, no.
Brian
+1  A: 

On Ubuntu (and similar):

$ update-java-alternatives --list
java-1.5.0-sun 53 /usr/lib/jvm/java-1.5.0-sun
java-6-openjdk 1061 /usr/lib/jvm/java-6-openjdk
java-6-sun 63 /usr/lib/jvm/java-6-sun
$ update-java-alternatives --set java-1.5.0-sun
sfussenegger