Java 无法在 32 位 JVM 上加载 64 位 SWT 库(即使我下载了 32 位 SWT)

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

Cannot load 64-bit SWT libraries on 32-bit JVM (even though I downloaded 32-bit SWT)

javaeclipsex86swt64-bit

提问by roosevelt

I am currently developing on a 64-bit Windows 7 machine. I have JRE7 64-bit and JRE7 32-bit installed on my machine. I am using Eclipse 64-bit version and configured Window - Preferences - Java - Installed JREs to use JRE7 32-bit to be my default JRE to test against. Also installed the 32-bit JDK and currently using that to test against.

我目前正在 64 位 Windows 7 机器上开发。我的机器上安装了 JRE7 64 位和 JRE7 32 位。我正在使用 Eclipse 64 位版本并配置 Window - Preferences - Java - Installed JREs 以使用 JRE7 32 位作为我测试的默认 JRE。还安装了 32 位 JDK,目前正在使用它进行测试。

I double checked and made sure I am indeed using SWT 32-bit Windows but still during compilation it throws me the "Cannot load 64-bit SWT libraries on 32-bit JVM" error.

我再次检查并确保我确实在使用 SWT 32 位 Windows,但在编译期间它仍然抛出“无法在 32 位 JVM 上加载 64 位 SWT 库”错误。

The error clearly indicates that Eclipse is indeed using JDK7-32 Bit but for some reason the SWT Libraries (http://www.eclipse.org/downloads/download.php?file=/eclipse/downloads/drops4/R-4.3-201306052000/swt-4.3-win32-win32-x86.zip) is not fully 32-bit o.O...

该错误清楚地表明 Eclipse 确实在使用 JDK7-32 位,但出于某种原因使用了 SWT 库(http://www.eclipse.org/downloads/download.php?file=/eclipse/downloads/drops4/R-4.3- 201306052000/swt-4.3-win32-win32-x86.zip) 不是完全的 32 位 oO..

Any ideas? Any workarounds?

有任何想法吗?任何解决方法?

FYI, switching the JRE to 64-bit compiles the program just fine but I want my application to work on both 32-bit and 64-bit.

仅供参考,将 JRE 切换到 64 位可以很好地编译程序,但我希望我的应用程序能够在 32 位和 64 位上运行。

Here is the full exception:

这是完整的例外:

Exception in thread "main" java.lang.UnsatisfiedLinkError: Cannot load 64-bit SWT libraries on 32-bit JVM
    at org.eclipse.swt.internal.Library.loadLibrary(Library.java:260)
    at org.eclipse.swt.internal.Library.loadLibrary(Library.java:240)
    at org.eclipse.swt.internal.C.<clinit>(C.java:21)
    at org.eclipse.swt.widgets.Widget.<clinit>(Widget.java:107)
    at Test.Application.<init>(Application.java:19)a
    at Test.Application.main(Application.java:29)

采纳答案by Krease

SWT uses plugin fragments to control this - there is a 32-bit fragment and a 64-bit fragment (as well as fragments for Mac, Linux, etc). Make sure your launch configuration is set to use the proper fragment depending on which JVM you're running it on.

SWT 使用插件片段来控制它 - 有一个 32 位片段和一个 64 位片段(以及用于 Mac、Linux 等的片段)。确保您的启动配置设置为使用正确的片段,具体取决于您在哪个 JVM 上运行它。

As a note, just including "both" plugin fragments will not work, as then they will both attempt to load and cause problems.

请注意,仅包含“两个”插件片段将不起作用,因为它们都会尝试加载并导致问题。

Also, thisrelated question may be useful.

此外,这个相关问题可能有用。

Another idea would be to dive into the loadLibraryfunction - from what I remember of how that works, it looks for a cached version of the SWT dll from a temp location somewhere, and so it might be using a cached 64-bit dll instead of properly unpacking the 32-bit one from the jar. In that case, deleting the cached one may fix the issue.

另一个想法是深入研究该loadLibrary函数 - 从我记得它是如何工作的,它从某个临时位置查找 SWT dll 的缓存版本,因此它可能使用缓存的 64 位 dll 而不是正确的从 jar 中解压 32 位的。在这种情况下,删除缓存的可能会解决问题。

The easiest solution, though, may be just to have two separate instances of Eclipse:one setup to run 32-bit, one setup to run 64-bit. This way you don't have to worry about toggling back and forth, or futz around with configurations as much.

不过,最简单的解决方案可能只是拥有两个单独的 Eclipse 实例:一个设置运行 32 位,一个设置运行 64 位。这样您就不必担心来回切换,也不必担心配置。

回答by user3206144

"I am using Eclipse 64-bit version and configured Window - Preferences - Java - Installed JREs to use JRE7 32-bit to be my default JRE to test against."

“我正在使用 Eclipse 64 位版本并配置 Window - Preferences - Java - Installed JREs 以使用 JRE7 32 位作为我测试的默认 JRE。”

how about configure your eclipse to point and use a full blown 32-bit jdk instead of the jre for the project?

如何配置您的 eclipse 以指向并使用完整的 32 位 jdk 而不是项目的 jre?

回答by Annalakshmi

In your Eclipse click on

在你的 Eclipse 中点击

Run -> External Tools -> External Tools Configurations...

运行 -> 外部工具 -> 外部工具配置...

In JRE tab Choose the option

在 JRE 选项卡中选择选项

Run in the same JRE as workspace.

在与工作区相同的 JRE 中运行。



This fixed the issue for me.

这为我解决了这个问题。