如何检测安装了哪种 JRE——32 位与 64 位 [英] How do I detect which kind of JRE is installed -- 32bit vs. 64bit

查看:29
本文介绍了如何检测安装了哪种 JRE——32 位与 64 位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用 NSIS 安装程序进行安装期间,我需要检查系统上安装了哪个 JRE(32 位与 64 位).我已经知道我可以检查系统属性sun.arch.data.model",但这是特定于 Sun 的.我想知道是否有一个标准的解决方案.

During installation with an NSIS installer, I need to check which JRE (32bit vs 64bit) is installed on a system. I already know that I can check a system property "sun.arch.data.model", but this is Sun-specific. I'm wondering if there is a standard solution for this.

推荐答案

可以使用os.arch" 属性:

System.getProperty("os.arch");

os"部分似乎有点用词不当,或者可能最初的设计者没想到 JVM 会运行在他们不适合的架构上.返回值似乎不一致.

The "os" part seems to be a bit of a misnomer, or perhaps the original designers did not expect JVMs to be running on architectures they weren't written for. Return values seem to be inconsistent.

NetBeans 安装程序团队正在解决 JVM 与操作系统架构的问题.引用:

The NetBeans Installer team are tackling the issue of JVM vs OS architecture. Quote:

x64 位:Java 和系统

被跟踪为问题 143434.

目前我们使用 x64 位的 JVM 来确定系统(从而Platform.getHardwareArch()) 是 64 位的或不.这绝对是错误的,因为可以在 32 位 JVM 上运行64位系统.我们应该找到一个检查操作系统真实 64 位的解决方案如果在 32 位 JVM 上运行.

Currently we using x64 bit of JVM to determine if system (and thus Platform.getHardwareArch()) is 64-bit or not. This is definitely wrong since it is possible to run 32bit JVM on 64bit system. We should find a solution to check OS real 64-bitness in case of running on 32-bit JVM.

  • 对于 Windows,可以使用 WindowsRegistry.IsWow64Process() 来完成
  • 对于 Linux - 通过检查 'uname -m/-p' == x86_64
  • 对于 Solaris,可以使用例如'isainfo -b'
  • 对于 Mac OSX,不能使用 uname 参数来完成,可能可以通过创建 64 位二进制文​​件解决并在平台上执行...(不幸的是,这不起作用:(我只用 x86_64 创建了二进制文件和 ppc64 arch 并成功在老虎身上执行..)
  • 对于通用 Unix 支持 - 也不清楚......可能正在检查对于相同的 'uname -m/-p'/'getconfLONG_BIT' 并将其与一些比较可能的 64 位值(x86_64、x64、amd64、ia64).

<小时>

来自不同 JVM 的示例属性都在 64 位 Ubuntu 8.0.4 上运行:


Sample properties from different JVMs all running on 64bit Ubuntu 8.0.4:

32 位 IBM 1.5:

32bit IBM 1.5:

java.vendor=IBM Corporation
java.vendor.url=http://www.ibm.com/
java.version=1.5.0
java.vm.info=J2RE 1.5.0 IBM J9 2.3 Linux x86-32 j9vmxi3223-20061001 (JIT enabled)
J9VM - 20060915_08260_lHdSMR
JIT  - 20060908_1811_r8
GC   - 20060906_AA
java.vm.name=IBM J9 VM
java.vm.specification.name=Java Virtual Machine Specification
java.vm.specification.vendor=Sun Microsystems Inc.
java.vm.specification.version=1.0
java.vm.vendor=IBM Corporation
java.vm.version=2.3
os.arch=x86
os.name=Linux
os.version=2.6.24-23-generic
sun.arch.data.model=32

64 位 Sun 1.6:

64bit Sun 1.6:

java.vendor=Sun Microsystems Inc.
java.vendor.url=http://java.sun.com/
java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi
java.version=1.6.0_05
java.vm.info=mixed mode
java.vm.name=Java HotSpot(TM) 64-Bit Server VM
java.vm.specification.name=Java Virtual Machine Specification
java.vm.specification.vendor=Sun Microsystems Inc.
java.vm.specification.version=1.0
java.vm.vendor=Sun Microsystems Inc.
java.vm.version=10.0-b19
os.arch=amd64
os.name=Linux
os.version=2.6.24-23-generic
sun.arch.data.model=64

64 位 GNU 1.5:

64bit GNU 1.5:

java.vendor=Free Software Foundation, Inc.
java.vendor.url=http://gcc.gnu.org/java/
java.version=1.5.0
java.vm.info=GNU libgcj 4.2.4 (Ubuntu 4.2.4-1ubuntu3)
java.vm.name=GNU libgcj
java.vm.specification.name=Java(tm) Virtual Machine Specification
java.vm.specification.vendor=Sun Microsystems Inc.
java.vm.specification.version=1.0
java.vm.vendor=Free Software Foundation, Inc.
java.vm.version=4.2.4 (Ubuntu 4.2.4-1ubuntu3)
os.arch=x86_64
os.name=Linux
os.version=2.6.24-23-generic

(GNU 版本不报告sun.arch.data.model"属性;想必其他 JVM 也不报告.)

(The GNU version does not report the "sun.arch.data.model" property; presumably other JVMs don't either.)

这篇关于如何检测安装了哪种 JRE——32 位与 64 位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆