Java Windows 中的 JRE 安装目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3930383/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JRE installation directory in Windows
提问by Ankur
Is there any command to check the active (since the machine can have more than 1 JRE installed) JRE installation directory under Windows. For linux, the corresponding command is
有没有什么命令可以查看windows下的active(因为机器可以安装1个以上的JRE)JRE安装目录。对于linux,对应的命令是
which java
Is there any Windows equivalent ?
是否有任何 Windows 等价物?
采纳答案by Ian Dallas
where java
works for me to list all java exe but java -verbose
tells you which rt.jar
is used and thus which jre (full path):
where java
适用于我列出所有 java exe,但会java -verbose
告诉您rt.jar
使用了哪个 jre(完整路径):
[Opened C:\Program Files\Java\jre6\lib\rt.jar]
...
Edit: win7 and java:
编辑:win7 和 java:
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) 64-Bit Server VM (build 16.3-b01, mixed mode)
回答by Ian Dallas
In the command line you can type java -version
在命令行中,您可以键入 java -version
回答by Michael Mao
回答by glob
Not as a command, but this information is in the registry:
不是作为命令,但此信息在注册表中:
- Open the key
HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment
- Read the
CurrentVersion
REG_SZ - Open the subkey under
Java Runtime Environment
named with theCurrentVersion
value - Read the
JavaHome
REG_SZ to get the path
- 打开钥匙
HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment
- 读取
CurrentVersion
REG_SZ - 打开
Java Runtime Environment
named下的子CurrentVersion
键值 - 读取
JavaHome
REG_SZ 以获取路径
For example on my workstation i have
例如在我的工作站上我有
HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment
CurrentVersion = "1.6"
HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment.5
JavaHome = "C:\Program Files\Java\jre1.5.0_20"
HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment.6
JavaHome = "C:\Program Files\Java\jre6"
So my current JRE is in C:\Program Files\Java\jre6
所以我目前的 JRE 在 C:\Program Files\Java\jre6
回答by glob
Following on from my other comment, here's a batch file which displays the current JRE or JDK based on the registry values.
继我的其他评论之后,这里有一个批处理文件,它根据注册表值显示当前的 JRE 或 JDK。
It's different from the other solutions in instances where java is installed, but not on the PATH
.
在安装 java 的情况下,它与其他解决方案不同,但在PATH
.
@ECHO off
SET KIT=JavaSoft\Java Runtime Environment
call:ReadRegValue VER "HKLM\Software\%KIT%" "CurrentVersion"
IF "%VER%" NEQ "" GOTO FoundJRE
SET KIT=Wow6432Node\JavaSoft\Java Runtime Environment
call:ReadRegValue VER "HKLM\Software\%KIT%" "CurrentVersion"
IF "%VER%" NEQ "" GOTO FoundJRE
SET KIT=JavaSoft\Java Development Kit
call:ReadRegValue VER "HKLM\Software\%KIT%" "CurrentVersion"
IF "%VER%" NEQ "" GOTO FoundJRE
SET KIT=Wow6432Node\JavaSoft\Java Development Kit
call:ReadRegValue VER "HKLM\Software\%KIT%" "CurrentVersion"
IF "%VER%" NEQ "" GOTO FoundJRE
ECHO Failed to find Java
GOTO :EOF
:FoundJRE
call:ReadRegValue JAVAPATH "HKLM\Software\%KIT%\%VER%" "JavaHome"
ECHO %JAVAPATH%
GOTO :EOF
:ReadRegValue
SET key=%2%
SET name=%3%
SET "%~1="
SET reg=reg
IF DEFINED ProgramFiles(x86) (
IF EXIST %WINDIR%\sysnative\reg.exe SET reg=%WINDIR%\sysnative\reg.exe
)
FOR /F "usebackq tokens=3* skip=1" %%A IN (`%reg% QUERY %key% /v %name% 2^>NUL`) DO SET "%~1=%%A %%B"
GOTO :EOF