How to manage a local multi-JDK environment for Windows

This article has participated in the "Newcomer Creation Ceremony" event to start the road of gold creation together.

foreword

Java program development is inseparable from tools , because good tools can allow us to focus more on development itself

  • For example: IDE , Eclipse

Tools have the advantages of tools, it can even avoid the selection and configuration of JDK during our project development

However , in some cases, we still need to control the Java command or environment locally , for example: Setting up Ali cache technology under Windows : jetCache requires JDK8 version

  • image.png

So how to freely switch the local IDE version? Let's find out together.

Do I have to go to the official website to install the JDK?

I don't think it is necessary, why do you say that? Unless we are working on individual projects, when the Jar package has strict requirements for the JDK version, we need to download it from the official website at this time.

image.png


During normal development, we can download the corresponding JDK through the IDE tool , and the tool automatically configures the environment.

In order to take care of all the students who are beginners in Java who have trouble with the environment configuration, here are two ways to configure and install JDK.

Installing Window JDK on the official website takes 18 as an example

download

In fact, you can still find the download through the connection point above , download the Installer version

More versions can be found in the picture below:

image.png image.png image.png

Install

Confirm the installation locationimage.png

Now installing JDK will give you configuration environment variables by default

at this address:C:\Program Files\Common Files\Oracle\Java\javapath

image.png

We need to delete this environment in the system path variable or move to the bottom

image.png

Configure environment variables

New JAVA18_HOMEsystem variable

image.png

Select the directory where the JDK is installed

image.png

Create a new JAVA_HOMEsystem variable, the variable value is%JAVA18_HOME%

image.png

means by JAVA_HOMEpointing toJDK18这个目录

Add environment variables to Path

image.pngenter:%JAVA_HOME%\bin

IDE tool to download JDK

Click on Project Structure

image.png

Click the plus sign to download

Select the corresponding version and download locationimage.png

version switch

Just replace JAVA_HOMEthe value inside, the actual version name is mainly named by yourselfimage.png

Summarize

The configuration of the original environment

graph TD
JAVA_Home --> path

Multi-environment management configuration now

erDiagram
Java8_Home }|--o{ Java_Home : use
Java_Home ||--|{ path : get
Java18_Home }|..o{ Java_Home : unuse

By setting the form of variables, changing the value of JAVA_Home can realize the switching of JDK versions

test

use:java -version

Go try your JDK multi-environment configuration!

Guess you like

Origin juejin.im/post/7101664982386868232