多个版本JDK切换

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

@echo off

rem --- Base Config ---
:init 
set JAVA_HOME_1_8=D:\DevTools\Java\jdk1.8.0_01
set JAVA_HOME_1_7=D:\DevTools\Java\jdk1.7.0_45
set JAVA_HOME_1_6=D:\DevTools\Java\jdk1.6.0_45

: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 --- set path ---
set jhb=%TARGET_JAVA_HOME%\bin
set pt=%Path%

call set pt=%%pt:%jhb%;=%%
call set pt=%%pt:%jhb%=%%

wmic ENVIRONMENT where "name='Path' and username='<system>'" set VariableValue="%jhb%;%pt%"

rem -- refresh env ---
call RefreshEnv
@echo on