头图

1. Download JDK

Windows download has the following three options: (take the latest version jdk17 as an example)

Product/file descriptionFile sizeDownload
x64 Compressed Archive170.66 MBhttps://download.oracle.com/java/17/latest/jdk-17_windows-x64_bin.zip (sha256 )
x64 Installer152 MBhttps://download.oracle.com/java/17/latest/jdk-17_windows-x64_bin.exe (sha256 )
x64 MSI Installer150.89 MBhttps://download.oracle.com/java/17/latest/jdk-17_windows-x64_bin.msi (sha256 )

I personally prefer the compressed package version, which is the first one. After the download is complete, it can be decompressed directly. The decompressed directory structure is:

├─bin
├─conf
├─include
├─jmods
├─legal
└─lib

More versions can be downloaded http://jdk.java.net/

2. Generate JRE

You can see that there is no jre directory in the directory, here you can use the command to generate it

Go to the bin directory and run:

./jlink.exe --module-path jmods --add-modules java.desktop --output ../jre

The current directory structure is:

├─bin
├─conf
├─include
├─jmods
├─jre
├─legal
└─lib

3. Configure the amount of environment

Copy the directory address and add system environment variables

variable nameJAVA_HOME
variableD:\dev\jdk-17.0.1

Edit the path environment variable and create the following two

%JAVA_HOME%\bin

%JAVA_HOME%\jre\bin

4. Check the installation results

Run the following command in the command line:

java -version

Appear:

java version "17.0.1" 2021-10-19 LTS
Java(TM) SE Runtime Environment (build 17.0.1+12-LTS-39)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.1+12-LTS-39, mixed mode)

run:

javac

Appear:

用法: javac <options> <source files>
其中, 可能的选项包括:
  @<filename>                  从文件读取选项和文件名
  -Akey[=value]                传递给注释处理程序的选项
  --add-modules <模块>(,<模块>)*
        除了初始模块之外要解析的根模块; 如果 <module>
                为 ALL-MODULE-PATH, 则为模块路径中的所有模块。
 ...

Is success

5. Switching between multiple versions of JDK

Switching method

  1. Change the JAVA_HOME in the system environment variable to the jdk path of the required version
  2. Run java -version to view the jdk version

problem solved

If the environment variable does not take effect after the change

  1. Restart the computer
  2. Move [%JAVA_HOME%\bin, %JAVA_HOME%\jre\bin] in the path in the system environment variable to the front

akazwz
100 声望4 粉丝

Hello World!