Tuesday, January 03, 2012

Batch script to change Java Home between different JDKs

I recently happened to be working on multiple releases with some of them requiring the code to be compiled with JDK 6 whereas the more recent releases requiring code to compile with JDK 7. So i wrote up the following batch script to make the job of switching between the 2 JDKs easier. Before i run my ant build script i run the below script to set to ‘7’ for JDK 7 or ‘6’ for JDK 6.

echo %1%
if "%1"== "" ( 
    echo "Syntax: javahome 7 or 6" 
    Goto :end
if "%1" == "7" (
    echo "Setting JDK 7"
    set JAVA_HOME=C:\Program Files\Java\jdk1.7.0_01
    GOTO :printver
if "%1" == "6" (
    echo "Setting JDK 6"
    set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_23
    GOTO :printver
echo %JAVA_HOME%
FOR /F "delims=;" %%P IN ("%PATH%") DO (
    @ECHO path = %%~P
echo %PATH%
java -version

No comments:

Book Review: The Sign of Four by Arthur Conan Doyle

The Sign of Four by Arthur Conan Doyle My rating: 5 of 5 stars It is the second Sherlock Holmes book after "A Study in Scarlet&quo...