JRE installation directory in Windows [closed]
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this questionIs 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
which java
Is there any Windows equivalent ?
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):
[Opened C:\Program Files\Java\jre6\lib\rt.jar]
...
Edit: win7 and 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)
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
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\1.5
JavaHome = "C:\Program Files\Java\jre1.5.0_20"
HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.6
JavaHome = "C:\Program Files\Java\jre6"
So my current JRE is in C:\Program Files\Java\jre6
Following on from my other comment, here's a batch file which displays the current JRE or JDK based on the registry values.
It's different from the other solutions in instances where java is installed, but not on the 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
Look the answer to my previous question here
c:\> for %i in (java.exe) do @echo. %~$PATH:i
C:\WINDOWS\system32\java.exe
In the command line you can type java -version
精彩评论