Go to "Use batch scripts to implement multiple versions of JDK switching under windows

Source: Internet
Author: User

Original blog from: http://www.cnblogs.com/xdp-gacl/p/5209386.html thanks!

I. JDK version switch batch script

When we are doing development on window, we may need to develop two or more projects at the same time, and sometimes different projects will differ on the JDK version requirements, when we may install multiple versions of the JDK on a single computer, as shown in:

  

When we want to switch between the JDK versions we use, we can do two things:

1. To manually modify the JAVA_HOME environment variable, point the value of the variable to the installation directory of the corresponding JDK version.

2. It is a lazy practice to dynamically modify the value of the JAVA_HOME environment variable by writing a batch script based on the selected JDK version, which requires a RefreshEnv.exe auxiliary software to refresh the values of the environment variables

Found a section on the Internet can dynamically modify the Java_home environment batch script, so that the JDK version of the dynamic switch, the script code is as follows:

 1 @echo off 2 3 rem---Base Config configuration JDK installation directory---4:init 5 set java_home_1_8=c:\program Files\java\jdk1.8.0_11 6 Set Java_home_1_7=c:\program files\java\jdk1.7.0_45 7 set Java_home_1_6=c:\program files\java\jdk1.6.0_45 8:start 9 Ech o JDK version currently in use: java-version echo. Echo ============================================= echo JDK version list echo 1.8 echo 1.716 echo 1.6 echo ========= ==================================== 19:select20 set/p opt= Please select JDK version: If%opt%==1.8 (set Target_java_home=%j ava_home_1_8%23) if%opt%==1.7 (set target_java_home=%java_home_1_7%26) if%opt%==1.6 (set Target_java _home=%java_home_1_6%29) echo the currently selected JAVA path:%target_java_home%32 WMIC environment where "name= ' Java_home '" DELETE34 WMIC Environment Create Name= "Java_home", username= "<system>", variablevalue= "%target_java_home%" 35 36   REM--Refresh env---notoginseng call RefreshEnv38-echo please press any key to exit! pause>nul41 @echo on 

This batch script code is dynamically modifying the JAVA_HOME environment variable according to the JDK version we chose, and then RefreshEnv.exe to refresh the value of the environment variable.

two. How to use

Save the batch script code above as a. bat file, and place the RefreshEnv.exe auxiliary software and the. bat script file in the same directory as shown in:

  

Double-click the. bat file to run the batch script, as shown in the following instructions:

  

When execution is complete, the value of the JAVA_HOME environment variable is modified to the corresponding JDK version of the installation directory.

  

  

This batch script only modifies the value of the JAVA_HOME environment variable and does not affect the value of the path variable, so you can use it with confidence. To make it easy for everyone to use, I'll share the tool for you, JDK version switch tool download

Go to "Use batch scripts to implement multiple versions of JDK switching under windows

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.