Install and configure multiple versions of JDK

Time:2022-5-28

Preface: there are multiple versions of JDK. Sometimes it is necessary to switch different versions for development. To install multiple jdks on a computer, you only need to configure them as follows, and you can easily use them each time. The following environments are windows10

Install JDK

Install jdk8

Configure environment variables

Configuration requiredJAVA_HOME CLASSPATH PathCLASSPATHandPathNormal configurationJAVA_HOME, you need to create a custom variable to save the JDK location. The following takes variables jdk1 and jdk2 as examples

Jdk1:{jdk1_; installation location}

Jdk2:{jdk2_installation location}

JAVA_HOME

%{JDK1}%: jdk1 version is effective

%{JDK2}%: jdk2 version is effective

This configuration only needs to be changed every time another version of JDK is requiredJAVA_HOMEAs shown in the following figure:

Snipaste_2021-08-20_18-13-46

CLASSPATH

Period and semicolon of English characters are in front of them. If you need to add English semicolons after them

.;%JAVA_HOME%\lib

Path

%JAVA_HOME%\bin

Test JDK environment

Open a command prompt and enterjava -version, the correct version information is displayed, that is, the configuration is successful

javajavacThese two commands can also be tested. When a pile of information appears, the configuration is successful