When we develop on Windows, we may need to develop two or more projects at the same time, sometimes different projects differ in the JDK version requirements, and in order to simplify the operation, we can complete the task of environment variable switching through batch files.
How to:
Read the code we will find that we only need to modify our JDK installation directory, and then save the bat file, double-click the bat file to start running, according to the prompts to operate.
@echo Off:init set Java_home_1_7=c:\program files\java\jdk1.7.0_22 set Java_home_1_6=d:\program Files\Java\jdk1.6.0 _27 set Eclipse_exe=d:\tools\dev (eclipse3.3) \eclipse.exe:start echo JDK version: Java-version ping 127.0.0.1-n 2-w 1
M > nul echo. Echo ============================================= echo JDK version list echo 1.7 echo 1.6 echo =============================== ==============: Select set/p opt= Please select JDK version: If%opt%==1.7 (start/i/wait/b WMIC environment where Name= ' Java_home ' Set variablevalue= '%java_home_1_7% ' >nul rem reg add ' hkey_local_machine\system\currentcontrolset\control\ Session Manager\Environment "/V java_home/t reg_sz/d"%java_home_1_7% "/F goto Success) if%opt%==1.6 (start/i /wait/b WMIC environment where name= ' java_home ' Set variablevalue= "%java_home_1_6%" >nul rem reg ADD "Hkey_local_mach Ine\system\currentcontrolset\control\session manager\environment "/V java_home/t reg_sz/d"%JAVA_HOME_1_6% "/F goto su ccess) EchO Selected version error, please choose again!
PAUSE Goto start:success Echo.
The Echo settings environment has changed successfully. Ping 127.0.0.1-n 2-w 1000 > nul taskkill/f/im eclipse.exe ping 127.0.0.1-n 3-w 1000 > nul start%ECLIPSE_EX
E%
The above is the entire contents of this article, I hope you can enjoy.