Using batch processing to switch JDK environment variables under Windows _dos/bat

Source: Internet
Author: User
Tags goto

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.