« Blog your code using SyntaxHighlighter | Main | Configuring ScribeFire for Movable Type »

Switch between different JDK versions in Windows

java.pngBeing a Java developer, I always compile and test my code on different Java versions. But switching between them is a huge problem. So finally I found an easy method to do this. You have to create following batch files and place them in directory you open your command line in or in SYSTEM PATH. You can use you favorite text editor to create these files.

jdk14.bat

@echo off
echo Setting JAVA_HOME
set JAVA_HOME=C:\j2sdk1.4.2_12
echo setting PATH
set PATH=C:\j2sdk1.4.2_12\bin;%PATH%
echo Display java version
java -version

jdk15.bat

@echo off
echo Setting JAVA_HOME
set JAVA_HOME=C:\Program Files\Java\jdk1.5.0_12
echo setting PATH
set PATH=C:\Program Files\Java\jdk1.5.0_12\bin;%PATH%
echo Display java version
java -version

jdk16.bat

@echo off
echo Setting JAVA_HOME
set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_11
echo setting PATH
set PATH=C:\Program Files\Java\jdk1.6.0_11\bin;%PATH%
echo Display java version
java -version

Make sure you assign the appropriate JAVA_HOME value in batch files, according to your Java installation. Whenever you want to switch between Java versions, just run the respective batch file and you are done.

Note- JAVA_HOME and the path to java must always refer to the exact same version of the JDK. If you mix them up, unpredictable things will happen!

TrackBack

TrackBack URL for this entry:
http://blogs.oracle.com/mt/mt-tb.cgi/8955

Comments (2)

Your note is very true, so make sure you don't run more than one batch file in the same command-window. Close the command window and open a new one first.

why don“t use te JAVA_HOME variable for setting the PATH variable?
Like this:

@echo off
echo Setting JAVA_HOME
set JAVA_HOME=C:\Archivos de programa\Java\jdk1.6.0_07
echo setting PATH
set PATH=%JAVA_HOME%\bin;%PATH%
echo Display java version
java -version

This way we reduce the risks you mention

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About This Entry

This page contains a single entry from the blog posted on December 14, 2008 12:06 AM.

The previous post in this blog was Blog your code using SyntaxHighlighter.

The next post in this blog is Configuring ScribeFire for Movable Type.

Many more can be found on the main index page or by looking through the archives.

Creative Commons License
This weblog is licensed under a Creative Commons License.
Powered by
Movable Type and Oracle