如何使用 SWT/Eclipse 在 Mac OS X 中执行 jar?

发布于 2024-12-17 03:45:11 字数 1260 浏览 0 评论 0原文

我将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.

Error dialog

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

独守阴晴ぅ圆缺 2024-12-24 03:45:11

试试这个:

java -d32 -XstartOnFirstThread -jar myapp.jar

-d32 选项将使虚拟机在 32 位模式下运行。 -XstartOnFirstThread 选项对于 SWT 应用程序是必需的。

Try this:

java -d32 -XstartOnFirstThread -jar myapp.jar

The -d32 option will cause the VM to run in 32-bit mode. The -XstartOnFirstThread option is necessary for SWT applications.

痴意少年 2024-12-24 03:45:11

问题是不是 Eclipse 正在执行您构建的 jar,而是 Finder/java 启动器。您需要做的是转到 /Applications/Utilities/Java Preferences.app 并重新排序(单击拖动),以便在 64 位版本之前选择您的 32 位版本。作为参考,我的看起来像这样:

My Java Preferences

然后当您执行 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:

My Java Preferences

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 use open app.jar it should work.

以酷 2024-12-24 03:45:11
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

请重点关注这个错误。您需要 64 位依赖库来启动它。这取决于默认加载的java。如果是 32 位包,则需要将默认 jvm 类路径设置为 32 位 java.lang.Classpath。您可以选择在 Eclipse 中更改它。

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

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.

绿光 2024-12-24 03:45:11

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:

String osArch = System.getProperty ("sun.arch.data.model");
if (osArch == null) {
    osArch = System.getProperty ("com.ibm.vm.bitmode");
}
URLClassLoader classLoader = (URLClassLoader) JarLoaderUtils.class.getClassLoader();
URL.setURLStreamHandlerFactory(new RsrcURLStreamHandlerFactory(classLoader));
Method addUrlMethod = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
addUrlMethod.setAccessible(true);
swtFileName = osArch.contains("64") ? SWT_MAC_x86_64 : SWT_MAC_x86;
URL swtFileUrl = new URL("rsrc:" + swtFileName);
addUrlMethod.invoke(classLoader, swtFileUrl);

请注意,您似乎在 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:

String osArch = System.getProperty ("sun.arch.data.model");
if (osArch == null) {
    osArch = System.getProperty ("com.ibm.vm.bitmode");
}
URLClassLoader classLoader = (URLClassLoader) JarLoaderUtils.class.getClassLoader();
URL.setURLStreamHandlerFactory(new RsrcURLStreamHandlerFactory(classLoader));
Method addUrlMethod = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
addUrlMethod.setAccessible(true);
swtFileName = osArch.contains("64") ? SWT_MAC_x86_64 : SWT_MAC_x86;
URL swtFileUrl = new URL("rsrc:" + swtFileName);
addUrlMethod.invoke(classLoader, swtFileUrl);

Note that you seem to run your app in macosx, you should also add the -XstartOnFirstThread option.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文