简体   繁体   中英

How to find the JRE path on Windows using command line

java -XshowSettings:properties -version | findstr "java.home" java -XshowSettings:properties -version | findstr "java.home" doesn't work, because it prints multiple lines.

Oddly enough, described java output goes to STDERR text stream. Apply 2>&1 redirection as follows:

2>&1 java -XshowSettings:properties -version | findstr "java\.home"
  java.home = C:\\Program Files\\Java\\jre1.8.0_201 

The same in ˙wsl˙ (Ubuntu) command prompt:

java.exe -XshowSettings:properties -version 2>&1 | grep "java\.home"
  java.home = C:\\Program Files\\Java\\jre1.8.0_201 

JAVA_HOME is not set by default in Windows Java. Instead, it lists itself in the registry. The value CurrentVersion in HKLM\\SOFTWARE\\JavaSoft\\Java Runtime Environment indicates the version, and JavaHome under HKLM\\SOFTWARE\\JavaSoft\\Java Runtime Environment\\{version} provides the path.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM