在 Windows 10 上检测 Java 虚拟机架构

Detecting Java VM architecture on Windows 10

我有以下代码来检测我的应用程序是否在 64 位平台上 运行ning:

public static boolean is64BitVM() {
  String bits = System.getProperty("sun.arch.data.model", "?");
  logger.debug(String.format("sun.arch.data.model=%s", bits));
  if (bits.equals("64")) {
     return true;
  }
  String java_vm_name = System.getProperty("java.vm.name");
  logger.debug(String.format("java.vm.name=%s", java_vm_name));      

  String os_arch = System.getProperty("os.arch");
  logger.debug(String.format("os.arch=%s", os_arch));

  if (bits.equals("?")) {
     // probably sun.arch.data.model isn't available
     // maybe not a Sun JVM?
     // try with the vm.name property
     return java_vm_name.toLowerCase().indexOf("64") >= 0;
    } 
  // probably 32bit
  return false;
}

它曾经在 Windows 7 上很好地 运行,但在升级到 Windows 10 后,同一段代码开始报告 32 位架构:

2015-11-05 17:53:15,429 DEBUG [javawsApplicationMain] sun.arch.data.model=32
2015-11-05 17:53:15,431 DEBUG [javawsApplicationMain] java.vm.name=Java   HotSpot(TM) Client VM
2015-11-05 17:53:15,431 DEBUG [javawsApplicationMain] os.arch=x86

奇怪的是,当通过 JWS 运行 时它报告 32 位架构,但是当我 运行 它在我的 IDE 本地时,我得到正确的结果(64 位). Windows 10 安全模型似乎是另一个令人毛骨悚然的问题。 有什么想法吗?

有效的解决方案是卸载 32 位版本,然后安装最新的 64 位版本 Java。起初我安装了 Java 8 但我无法强制启动我的 JWS 应用程序(即使将自签名证书添加到异常以及 .jnlp 文件中的 URL 也无济于事)。最终安装了最新的 Java 7 并且成功了。