简体   繁体   English

从Windows Command Promt知道JRE是32位还是64位

[英]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. 我想知道是否可以通过Windows命令提示符确定JRE是32位还是64位。 I want to use it in a Windows Script to modifiy the java.library.path, because I use DLLs in 32 or 64 bits. 我想在Windows脚本中使用它来修改java.library.path,因为我使用32位或64位DLL。 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. 因此,我想使用64位JRE使用“ java -cp blabla -Djava.library.path = bin / x64”启动Java程序,并使用“ java -cp blabla -Djava.library.path = bin / x86”启动Java程序”和一个32位的JRE。 Any ideas ? 有任何想法吗 ?

Thanks in advance, Cédric 预先感谢,塞德里克

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 -version output to a temporary file and then searches if that file contains the string "64". 它将java -version输出转储到一个临时文件,然后搜索该文件是否包含字符串“ 64”。 If this is the case it sets the environment variable JAVA_VERSION to 64 , else it is set to 32 . 如果是这种情况,它将环境变量JAVA_VERSION64 ,否则将其设置为32

Of course you can adapt this script to setup a JAVA_LIBPATH variable instead. 当然,您可以改写此脚本来设置JAVA_LIBPATH变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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