tools - batch script to switch JRE runtime path

6 篇文章 0 订阅
3 篇文章 0 订阅

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 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值