Total Pageviews

Tuesday, February 5, 2013

Batch file which can run on two or more Java/Jre version

Suppose you have a requirement to install a product/application on different type of hardware some of them uses Java/Jre5 and rest of them uses Java/Jre6 and we needed a single batch or sh file which can identify version according to hardware and install the application into the machine.

Here you go, this batch file will help you to implement these kind of requirements.




@echo off
REM Author @Kapil Pant
set JAVA_VERSION=1.6
set JAVA_VERSION2=1.4
if "%JAVA_HOME%" == "" goto javahomenotfound

REM Find Java executable

if not exist "%JAVA_HOME%\bin\java.exe" goto setjre
set JAVAEXE=%JAVA_HOME%\bin\java.exe
goto setjava
:setjre

if not exist "%JAVA_HOME%\jre\bin\java.exe" goto javahomenotfound
set JAVAEXE=%JAVA_HOME%\jre\bin\java.exe
:setjava

REM Verify correct Java version is being used
"%JAVA_HOME%\bin\java" -version 2>&1  | findstr /C:"%JAVA_VERSION1%"
If %ERRORLEVEL% EQU 0 goto goodversion
"%JAVA_HOME%\bin\java" -version 2>&1  | findstr /C:"%JAVA_VERSION2%"
If %ERRORLEVEL% NEQ 0 goto badjavaversion
:goodversion
set PATH=%JAVA_HOME%\bin;%PATH%
goto EOF

:javahomenotfound
echo You must set JAVA_HOME to a JRE or JDK
goto EOF

:badjavaversion
echo
echo Required Java %JAVA_VERSION% not found under %JAVA_HOME%
goto EOF
:EOF



No comments:

Post a Comment