简体   繁体   English

在Windows 10上检测Java VM体系结构

[英]Detecting Java VM architecture on Windows 10

I have following piece of code to detect if my app is running on 64-bit platform: 我有以下代码来检测我的应用程序是否在64位平台上运行:

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;
}

It used to run nicely on Windows 7, but after upgrade to Windows 10 the same piece of code started to report 32bit architecture: 它曾经在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

What is strange is that it reports 32-bit architecture when run through JWS, but when I run it locally in my IDE I get proper result (64-bit). 奇怪的是,当通过JWS运行时,它报告32位体系结构,但是当我在IDE中本地运行它时,会得到正确的结果(64位)。 Seems to be another freaking issue with Windows 10 security model. Windows 10安全模型似乎是另一个令人毛骨悚然的问题。 Any thoughts? 有什么想法吗?

The solution that worked was to uninstall 32-bit version and then install latest 64-bit Java. 有效的解决方案是卸载32位版本,然后安装最新的64位Java。 At first I have installed Java 8 but I could not force my JWS app to be launched (even adding self-signed cert to exceptions as well as URL from .jnlp file did not help). 最初,我已经安装了Java 8,但无法强制启动JWS应用程序(即使将自签名证书添加到异常以及.jnlp文件中的URL也无济于事)。 Eventually installed latest Java 7 and that did the trick. 最终安装了最新的Java 7,并且成功了。

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

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