Raccoon
Raccoon

Reputation: 63

Know if JRE is 32 or 64 bit from Windows Command Promt

I want to know if there is a way to determine, from the Windows Command Prompt, if the JRE is 32 or 64 Bit. I want to use it in a Windows Script to modifiy the java.library.path, because I use DLLs in 32 or 64 bits. So, I want to launch my Java Program with "java -cp blabla -Djava.library.path=bin/x64" with a 64 bits JRE and launch it with "java -cp blabla -Djava.library.path=bin/x86" with a 32 bits JRE. Any ideas ?

Thanks in advance, Cédric

Upvotes: 0

Views: 1348

Answers (1)

wero
wero

Reputation: 32980

Command line wizards may find a smaller solution but this works:

 java -version 2>javaversion.tmp
 set JAVA_VERSION=
 for /F "usebackq" %%A in (`findstr /C:"64-Bit" javaversion.tmp`) do set JAVA_VERSION=64
 if %JAVA_VERSION%.==. set JAVA_VERSION=32
 del javaversion.tmp

It dumps the java -versionoutput to a temporary file and then searches if that file contains the string "64". If this is the case it sets the environment variable JAVA_VERSION to 64, else it is set to 32.

Of course you can adapt this script to setup a JAVA_LIBPATH variable instead.

Upvotes: 1

Related Questions