如何使用 SWT/Eclipse 在 Mac OS X 中执行 jar?
我将Java更改为32位模式,以允许SWT运行,当我调试时,它运行良好。但是当我使用Eclipse导出.jar时,它显示这个错误。
我已经添加了 chmod 777。我做错了什么?
这是控制台结果:
20/11/2011 12:10:36 AM [0x0-0x3d89d86].com.apple.JarLauncher[73111] Exception in thread "main"
20/11/2011 12:10:36 AM [0x0-0x3d89d86].com.apple.JarLauncher[73111] java.lang.UnsatisfiedLinkError: Cannot load 32-bit SWT libraries on 64-bit JVM
20/11/2011 12:10:36 AM [0x0-0x3d89d86].com.apple.JarLauncher[73111] at org.eclipse.swt.internal.Library.loadLibrary(Unknown Source)
20/11/2011 12:10:36 AM [0x0-0x3d89d86].com.apple.JarLauncher[73111] at org.eclipse.swt.internal.Library.loadLibrary(Unknown Source)
20/11/2011 12:10:36 AM [0x0-0x3d89d86].com.apple.JarLauncher[73111] at org.eclipse.swt.internal.C.<clinit>(Unknown Source)
20/11/2011 12:10:36 AM [0x0-0x3d89d86].com.apple.JarLauncher[73111] at org.eclipse.swt.widgets.Display.<clinit>(Unknown Source)
20/11/2011 12:10:36 AM [0x0-0x3d89d86].com.apple.JarLauncher[73111] at com.testing.SWTApp.main(SWTApp.java:54)
MANIFEST 如下所示:
Manifest-Version: 1.0
Class-Path: .
Main-Class: com.testing.SWTApp
I changed the Java to 32 bit mode, to allow the SWT run, when I debug, it works well. But when I use Eclipse to export .jar, it shows this error.
I already added chmod 777. What did I do wrong?
Here is the console result:
20/11/2011 12:10:36 AM [0x0-0x3d89d86].com.apple.JarLauncher[73111] Exception in thread "main"
20/11/2011 12:10:36 AM [0x0-0x3d89d86].com.apple.JarLauncher[73111] java.lang.UnsatisfiedLinkError: Cannot load 32-bit SWT libraries on 64-bit JVM
20/11/2011 12:10:36 AM [0x0-0x3d89d86].com.apple.JarLauncher[73111] at org.eclipse.swt.internal.Library.loadLibrary(Unknown Source)
20/11/2011 12:10:36 AM [0x0-0x3d89d86].com.apple.JarLauncher[73111] at org.eclipse.swt.internal.Library.loadLibrary(Unknown Source)
20/11/2011 12:10:36 AM [0x0-0x3d89d86].com.apple.JarLauncher[73111] at org.eclipse.swt.internal.C.<clinit>(Unknown Source)
20/11/2011 12:10:36 AM [0x0-0x3d89d86].com.apple.JarLauncher[73111] at org.eclipse.swt.widgets.Display.<clinit>(Unknown Source)
20/11/2011 12:10:36 AM [0x0-0x3d89d86].com.apple.JarLauncher[73111] at com.testing.SWTApp.main(SWTApp.java:54)
The MANIFEST is like follow:
Manifest-Version: 1.0
Class-Path: .
Main-Class: com.testing.SWTApp
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
试试这个:
-d32
选项将使虚拟机在 32 位模式下运行。-XstartOnFirstThread
选项对于 SWT 应用程序是必需的。Try this:
The
-d32
option will cause the VM to run in 32-bit mode. The-XstartOnFirstThread
option is necessary for SWT applications.问题是不是 Eclipse 正在执行您构建的 jar,而是 Finder/java 启动器。您需要做的是转到
/Applications/Utilities/Java Preferences.app
并重新排序(单击拖动),以便在 64 位版本之前选择您的 32 位版本。作为参考,我的看起来像这样:然后当您执行
java -version
(没有-d
参数)您将获得选择的 32 位 JRE。当您在查找器中双击该 jar 或使用open app.jar
时,它应该可以工作。The problem is it's not Eclipse that is executing your built jar, it's Finder / the java launcher. What you need to do is goto
/Applications/Utilities/Java Preferences.app
and reorder (click drag) so that your 32 bit version is chosen before the 64 bit version. For reference mine looks like this:then when you execute
java -version
(no-d
parameter) you'll get the 32 bit JRE chosen. and when you double click the jar in finder or useopen app.jar
it should work.请重点关注这个错误。您需要 64 位依赖库来启动它。这取决于默认加载的java。如果是 32 位包,则需要将默认 jvm 类路径设置为 32 位 java.lang.Classpath。您可以选择在 Eclipse 中更改它。
Please focus on this error. You need 64-bit dependency libraries for launching it. It depends on default java loaded. If its 32-bit package, you need your default jvm classpath to be 32-bit java. You have option for changing it in eclipse.
swt jar 执行依赖于您的操作系统的本机库。
您有一个 swt 版本用于:
MacOSX 32 和64位
winsows 32 & 64位
Linux 32& 64 位
您可以指定
-d32
jvm 选项。它将强制 JVM 以 32 位模式运行。但是,您的操作系统中需要有 32 位 JVM 实现。您还可以在运行时动态加载正确的 SWT Jar:您在应用程序中包含两个 jar(swt-macosx-32bits 和 swt-macosx-64bits)并以编程方式加载所需的 jar:
请注意,您似乎在 macosx 中运行您的应用程序,您还应该添加
-XstartOnFirstThread
选项。the swt jar executes native librairies which depend on your OS.
You have one version of swt for:
macosx 32 & 64 bits
winsows 32 & 64 bits
linux 32 & 64 bits
you can specify the
-d32
jvm option. It will force the JVM to run in the 32 bits mode. However, you need to have a 32 bits implementation of the JVM available in your OS.You could also load dynamically at runtime the right SWT Jar: you include in your app both jar (swt-macosx-32bits & swt-macosx-64bits) and load programatically the required jar:
Note that you seem to run your app in macosx, you should also add the
-XstartOnFirstThread
option.