本机库,错误:此 Java 实例不支持 32 位 JVM

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15154557/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 18:39:56  来源:igfitidea点击:

Native Libraries, Error: This Java instance does not support a 32-bit JVM

javanetbeansjvmjava-native-library

提问by Matthew Sutter

Hello stackoverflow community,

你好,stackoverflow 社区,

I'm using NetBeans IDE 7.2.1, and I'm trying to compile+run a project with native libraries. My libraries require a 32 bit JVM. I'm running Windows 7 64-bit. When attempting to compile+run my project I'm met with the following:

我正在使用 NetBeans IDE 7.2.1,并且我正在尝试使用本机库编译+运行一个项目。我的库需要 32 位 JVM。我正在运行 Windows 7 64 位。在尝试编译+运行我的项目时,我遇到了以下问题:

    Error: This Java instance does not support a 32-bit JVM.
    Please install the desired version.
    Java Result: 1
    BUILD SUCCESSFUL (total time: 0 seconds)

I have tried going to configuration and included the following arguments (to no avail):

我尝试去配置并包含以下参数(无济于事):

    -d32
    -d32 -vm "C:\Program Files (x86)\Java\jre7\bin\javaw.exe" 
    -vm "C:\Program Files (x86)\Java\jre7\bin\javaw.exe"

I have both 64 bit JRE and 32 bit JRE installed, and both a 64 bit JDK and 32 bit JDK available in my platform manager.

我同时安装了 64 位 JRE 和 32 位 JRE,并且我的平台管理器中同时提供了 64 位 JDK 和 32 位 JDK。

Any suggestions to resolve this? I've read that you can get issues by installing the 64 bit JRE before the 32 bit JRE; is this one of those issues? (I have indeed installed 64 bit first)

有什么建议可以解决这个问题吗?我读过你可以通过在 32 位 JRE 之前安装 64 位 JRE 来解决问题;这是其中之一吗?(我确实先安装了 64 位)

采纳答案by 11684

When you start a process (for example on the command prompt, but it's the same AFAIK when you start another process from code) a certain group of paths (contained in the PATH (?) environment variable) is searched for an executable with a name matching what you entered. If the 64-bit and 32-bit version have the same name and the 64-bit version is found first, that one will be executed. I recommend specifying the full path of the 32-bit JDK.

当您启动一个进程时(例如在命令提示符下,但是当您从代码启动另一个进程时它是相同的 AFAIK)搜索特定组路径(包含在 PATH (?) 环境变量中)具有名称的可执行文件匹配您输入的内容。如果 64 位和 32 位版本具有相同的名称,并且首先找到 64 位版本,则将执行该版本。我建议指定 32 位 JDK 的完整路径。

EDIT:
I just saw the question is about the NetBeans IDE. I've never used that, so the only advice I can give you is to look in NetBeans' settings, and adjust the path to the JDK and JRE, making it point to the 32-bit version. I'll leave my answer here for people not using NetBeans.

编辑:
我刚刚看到问题是关于 NetBeans IDE。我从来没有用过它,所以我能给你的唯一建议是查看 NetBeans 的设置,并调整 JDK 和 JRE 的路径,使其指向 32 位版本。对于不使用 NetBeans 的人,我将在这里留下我的答案。

回答by bballdave025

Thanks to @11684 for the great answer. I would simply like to add a code example for those who compile from the command line/Command Prompt.

感谢@11684 的精彩回答。我只想为那些从命令行/命令提示符编译的人添加一个代码示例。

For the compilation, it shouldn't matter which javacgets used - 32-bit or 64-bit.

对于编译,javac使用哪个无关紧要- 32 位或 64 位。

>javac MyJavaProgramUsing32BitNativeLib.java

For the actual execution of the program, it isimportant to specify the path to the 32-bit version of java.exe

对于程序的实际执行,指定 32 位版本的路径重要java.exe

I'll post a code example for Windows, since that seems to be the OS used by the OP.

我将发布一个代码示例Windows,因为这似乎是 OP 使用的操作系统。

Windows

视窗

Most likely, the code will be something like:

最有可能的代码是这样的:

>"C:\Program Files (x86)\Java\jre#.#.#_###\bin\java.exe" MyJavaProgramUsing32BitNativeLib 

The difference will be in the numbers after jre. To find which numbers you should use, enter:

区别在于 之后的数字jre。要查找您应该使用的数字,请输入:

>dir "C:\Program Files (x86)\Java\"

On my machine, the process is as follows

在我的机器上,过程如下

C:\Users\me\MyProject>dir "C:\Program Files (x86)\Java"
 Volume in drive C is Windows
 Volume Serial Number is 0000-9999

 Directory of C:\Program Files (x86)\Java

11/03/2016  09:07 PM    <DIR>          .
11/03/2016  09:07 PM    <DIR>          ..
11/03/2016  09:07 PM    <DIR>          jre1.8.0_111
               0 File(s)              0 bytes
               3 Dir(s)  107,641,901,056 bytes free

C:\Users\me\MyProject>

So I know that my numbers are 1.8.0_111, and my command is

所以我知道我的号码是1.8.0_111,我的命令是

C:\Users\me\MyProject>"C:\Program Files (x86)\Java\jre1.8.0_111\bin\java.exe" MyJavaProgramUsing32BitNativeLib