Java SE 8安装之后,没有配置JAVA_HOME,CLASSPATH,PATH等系统变量的情况下,打开
cmd
,java -version
竟然有效,输出下java -verbose
可以查看详细信息。为了找到从哪里加载的java.exe
,我上网进行了一番搜索。终于找到了答案。
System Runtime Configuration File
中的System Runtime Configuration File章节说明了
After installing the JRE, the installer creates the system runtime configuration file.
In JDK 6, after using an installer configuration file to install the JRE, the installer saves it as a system runtime configuration file in%ALLUSERSPROFILE%\Oracle\Java\java_settings.cfg
.
In JDK 8 and above, after using an installer configuration file to install the JRE, the installer saves it as a system runtime configuration file inC:\Program Files (x86)\Common Files\Oracle\Java\java_settings.cfg
The value of the environment variable %ALLUSERSPROFILE% is typically C:\ProgramData
.
其中最重要的骚操作就是Oracle JDK/JRE把java相关的东西丢到了C:\Program Files (x86)\Common Files
下面,而这个文件夹默认是在系统变量PATH中的,这就造成了,你不配置JAVA_HOME等相关变量,照样能够使用Java相关的命令。
注意:JDK/JRE的行为在需要多版本JDK/JRE共存时容易产生问题,所以如果你需要使用指定的JDK/JRE版本时,请手动设置JAVA_HOME
或者在启动Java
应用的console
中提前设置JAVA_HOME
变量。
JAVA_HOME
,避免加载默认位置的JDK/JRE因为Java SE 8添加了
java.exe
,javaw.exe
等路径到系统变量,所以如果希望使用不同的JDK/JRE版本时,需要手动设置JAVA_HOME
。
因为Windows
在查找相关CMD
是安装顺序来查找的,所以把JAVA_HOME
放在PATH
环境变量的第一个,这样就能够使用指定的JDK/JRE版本。如果JAVA_HOME
放到C:\Program Files (x86)\Common Files\
之后,那么配置的JAVA_HOME
就不会生效。
Java SE 8 Update 171 Uses Different Windows Path (Doc ID 2412304.1)
Last updated on NOVEMBER 08, 2020
APPLIES TO:
Java SE JDK and JRE - Version 8 and later
Information in this document applies to any platform.
SYMPTOMS
When installing JRE 8 Update 171 for Windows x64, the Java installer (both .exe and Enterprise Installer) prepends the Windows Path environment variable with the 32-bit path:
C:\Program Files (x86)\Common Files\Oracle\Java\javapath
Previous 64-bit Java 8 releases (8 Update162 and older) prepend the 64-bit path: C:\ProgramData\Oracle\Java\javapath to the Windows Path environment variable.
The issue can be reproduced with the following steps:
Remove all Java installations
Clean up any lingering register keys with regedit
Clean up any lingering file/folder structures
Manually remove any javapath from Windows Path variable, if any exists after the uninstallation of Java
a. Open the System Control Panel
b. Click Advanced System Settings
c. Click Environement Variables
d. Under System Variables, double-click the Path variable
e. Remove any javapath path if present
Restart system
Use regedit to verify no Java registry keys or file artifacts remain
Verify Windows PATH does not contain any javapath
Install JRE 8u162
Verify the System Path variable is now prepended with 64-bit path: C:\ProgramData\Oracle\Java\javapath;
Remove JRE 8u162
Verify Windows PATH does not contain any javapath
Install JRE 8u171
Verify the System Path variable is prepended with 32-bit path: C:\Program Files (x86)\Common Files\Oracle\Java\javapath;
Java SE 8 Update 171 Uses Different Windows Path
use-installer-configuration-file-install-jre
which-jre-does-c-programdata-oracle-java-javapath-java-exe-use
how-to-set-custom-java-path-after-installing-jdk-8
原文:https://www.cnblogs.com/betgar/p/14604677.html