java 如何知道用户在swing面板中选择的JDK的位版本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11237161/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to know the bit version of JDK that selected by user in a swing panel
提问by Jemyxu
Our software has a swing panel that's used to list jdk installation paths. For example, if there are 4 jdk installed in user's PC and the jdk paths are listed in the panel:
我们的软件有一个摆动面板,用于列出 jdk 安装路径。例如,如果用户PC上安装了4个jdk,并且面板中列出了jdk路径:
C:\Java\jdk1.5.0_19\bin\java.exe
D:\software\Java6\jdk1.6.0_31\bin\java.exe
D:\software\Java6\jdk1.6.0_31_64\bin\java.exe
D:\installedapp\jdk1.7.0_03\bin\java.exe
C:\Java\jdk1.5.0_19\bin\java.exe
D:\software\Java6\jdk1.6.0_31\bin\java.exe
D:\software\Java6\jdk1.6.0_31_64\bin\java.exe
D:\installedapp\jdk1.7.0_03\bin\java.exe
The user needs to pick one of jdk installation paths to install our software. We want to know the bit version (32bit or 64bit) of jdk picked by user, how can we do that?
用户需要选择 jdk 安装路径之一来安装我们的软件。我们想知道用户选择的jdk的位版本(32位或64位),我们怎么做?
回答by Matt
well, if you know the location, you could probably use Runtime.exec("pathToJavaInstallPath/bin/java.exe -version")
and capture the version that way. That's at least one brute force way.
好吧,如果您知道该位置,您可能可以通过Runtime.exec("pathToJavaInstallPath/bin/java.exe -version")
这种方式使用和捕获版本。这至少是一种蛮力方式。
Sample output:
示例输出:
java version "1.6.0_32"
Java(TM) SE Runtime Environment (build 1.6.0_32-b05)
Java HotSpot(TM) 64-Bit Server VM (build 20.7-b02, mixed mode)
回答by Alexey Ivanov
You can also use GetBinaryType
Win32 API function to determine whether the given .exe is 32 or 64 bit.
您还可以使用GetBinaryType
Win32 API 函数来确定给定的 .exe 是 32 位还是 64 位。
See question How to detect that a given PE file (exe or dll) is 64 bit or 32 bitfor more details.
有关 更多详细信息,请参阅问题如何检测给定的 PE 文件(exe 或 dll)是 64 位还是 32 位。
回答by paulsm4
You can read the version of Java that's executing using the "java.version" property:
您可以使用“java.version”属性读取正在执行的 Java 版本:
You can also read the architecture (e.g. x86 vs amd64), OS and JRE home.
您还可以阅读架构(例如 x86 与 amd64)、操作系统和 JRE 主页。