In my BAT file I would like to have something like:
set javaVersion=...
if %javaVersion% equ 32 (
echo "do 32 Java routine"
) else (
echo "do non-32 Java routine"
)
On a 64bit machine, with JRE 64bit installed, in the registry under HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment and HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.6 I see almost the same values as on a 32bit machine with JRE 32bit installed:
HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment
CurrentVersion: 1.6
Java6FamilyVersion: 1.6.0_26
HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.6
JavaHome: C:\Program Files\Java\jre6
MicroVersion: 0
RuntimeLib: C:\Program Files\Java\jre6\bin\client\jvm.dll
Therefore, I could check if it is 64bit Java by checking if PROGRAMFILES(X86) is defined and if JavaHome points to location which starts with C:\Program Files\.
But is there a better option?
You could capture the output of
java -version– it’s in there.Here’s the output on my mac:
You should find either “64-Bit” or “32-Bit” in the output.