tools - batch script to switch JRE runtime path

If it very common that you may switch between different versions of JRE, either switching from a higher version to a lower version or from a x64 version to a x86 version. And normally if you have configure via the system settings some default JRE path, it is quite difficult when some rare application needs to run under a separate JRE runtime. 

Tinyumbrella is an example which requiresd a 32 bit JRE runtime. here is the script that you can use to start switch to a jre_x86 on windows 7, with some modification you can make it more generic to swing the JRE versions. 

@echo off
echo Staring x86 JRE environment on windowx 64 enviroment. 
echo ...
REM ====
REM 
REM   you can refer to this page for more details on how to use the  
REM      "Variable Edit/Replace" 
REM 
REM ====
call set PATH_HAS_JRE=0

if NOT DEFINED JAVA_HOME goto jre_not_set
call set OLD_JAVAHOME=%JAVA_HOME%
call :check_path "%JAVA_HOME%"
if %PATH_HAS_JRE%==0 goto :jre_not_set
echo remove %OLD_JAVAHOME%\bin; from %%PATH%%
call set PATH=%%PATH:%OLD_JAVAHOME%\bin;=%%

:jre_not_set
call set JAVA_HOME=C:\Program Files (x86)\Java\jdk1.7.0_07
call set CLASSPATH=.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar
call set PATH=%JAVA_HOME%\bin;%PATH%

echo Checking environment ...
call set JAVA_HOME
call set CLASSPATH
call :print_java_path "%JAVA_HOME%"

echo done
exit /b 0 
REM =====
REM  trick 
REM      "Finding items within the PATH environment variable"
REM   see  
REM       http://ss64.com/nt/syntax-replace.html
REM =====
:check_path
echo in %0
echo %%1=%1

REM ====
REM terminology
REM   %~f1 is a form of
REM      Parameter Extensions
REM ====
if not "%~dp$PATH:1" == "" call set PATH_HAS_JRE=1
echo exit %0...
goto :eof
REM ====
REM you can do 
REM   exit /b 0
REM as well
REM ====
exit /b 0 

:print_java_path
echo PATH=...%~dpn$PATH:1\bin;...
exit /b 0
@echo on 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章