windows下使用批处理实现切换JDK环境变量

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

@echo off

rem --- Base Config ---
:init 
set JAVA_HOME_1_8=D:\Program Files\Java\jdk1.8.0_60
set JAVA_HOME_1_7=D:\Program Files\Java\jdk1.7.0_51
set JAVA_HOME_1_6=D:\Program Files\Java\jdk1.6.0_31
set RefreshEnv=D:\JdkSwitch\switchVersion\RefreshEnv.exe

:start 
echo 当前JDK 版本: 
java -version 
ping 127.0.0.1 -n 2 -w 1000 > nul 
echo. 
echo ============================================= 
echo 本机JDK版本列表 
echo 1.8 
echo 1.7 
echo 1.6 
echo ============================================= 

:select
set /p opt=请选择JDK版本: 
if %opt%==1.8 (
    set TARGET_JAVA_HOME=%JAVA_HOME_1_8%
)
if %opt%==1.7 (
    set TARGET_JAVA_HOME=%JAVA_HOME_1_7%
)
if %opt%==1.6 (
    set TARGET_JAVA_HOME=%JAVA_HOME_1_6%
)

echo 当前选择的Java路径:%TARGET_JAVA_HOME%

wmic ENVIRONMENT where "name='JAVA_HOME'" delete
wmic ENVIRONMENT create name="JAVA_HOME",username="<system>",VariableValue="%TARGET_JAVA_HOME%"

rem -- refresh env ---
call %RefreshEnv%

echo 请按任意键退出!   
pause>nul

@echo on