http://www.cnblogs.com/xdp-gacl/p/5209386.html
1 @echo off 2 3 rem --- Base Config 配置JDK的安装目录 --- 4 :init 5 set JAVA_HOME_1_8=C:Program FilesJavajdk1.8.0_11 6 set JAVA_HOME_1_7=C:Program FilesJavajdk1.7.0_45 7 set JAVA_HOME_1_6=C:Program FilesJavajdk1.6.0_45 8 :start 9 echo 当前使用的JDK 版本: 10 java -version 11 echo. 12 echo ============================================= 13 echo jdk版本列表 14 echo 1.8 15 echo 1.7 16 echo 1.6 17 echo ============================================= 18 19 :select 20 set /p opt=请选择jdk版本: 21 if %opt%==1.8 ( 22 set TARGET_JAVA_HOME=%JAVA_HOME_1_8% 23 ) 24 if %opt%==1.7 ( 25 set TARGET_JAVA_HOME=%JAVA_HOME_1_7% 26 ) 27 if %opt%==1.6 ( 28 set TARGET_JAVA_HOME=%JAVA_HOME_1_6% 29 ) 30 31 echo 当前选择的Java路径:%TARGET_JAVA_HOME% 32 33 wmic ENVIRONMENT where "name='JAVA_HOME'" delete 34 wmic ENVIRONMENT create name="JAVA_HOME",username="<system>",VariableValue="%TARGET_JAVA_HOME%" 35 36 rem -- refresh env --- 37 call RefreshEnv 38 39 echo 请按任意键退出! 40 pause>nul 41 42 @echo on