在 Mac 上正确运行基于 SWT 的跨平台 jar
我一直在研究一个基于SWT的项目,该项目旨在部署为Java Web Start,因此可以在多个平台上使用。
到目前为止,我已经设法解决了由于SWT依赖的系统特定库而产生的导出问题(请参阅相关线程)。生成的jar似乎在32/64位linux和64位Windows上工作正常,但是在Mac上执行失败,并具有以下输出:
$ java -jar dist/test.jar
Adding { file:/Volumes/LaCie/ChiBE_Local/swt/swt-cocoa-macosx-x86_64-3.6.1.jar } to the classpath
***WARNING: Display must be created on main thread due to Cocoa restrictions.
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.lang.ExceptionInInitializerError
at org.eclipse.gef.tools.MarqueeSelectionTool.<init>(MarqueeSelectionTool.java:99)
at org.gvt.MarqueeZoomTool.<init>(MarqueeZoomTool.java:16)
at org.gvt.action.MarqueeZoomToolAction$1.<init>(MarqueeZoomToolAction.java:28)
at org.gvt.action.MarqueeZoomToolAction.createTool(MarqueeZoomToolAction.java:28)
at org.gvt.action.AbstractGEFToolAction.<init>(AbstractGEFToolAction.java:24)
at org.gvt.action.MarqueeZoomToolAction.<init>(MarqueeZoomToolAction.java:20)
at org.gvt.TopMenuBar.createBarMenu(TopMenuBar.java:113)
at org.gvt.ChisioMain.createMenuManager(ChisioMain.java:617)
at org.eclipse.jface.window.ApplicationWindow.addMenuBar(ApplicationWindow.java:235)
at org.gvt.ChisioMain.main(ChisioMain.java:149)
at org.gvt.RuntimeMain.main(RuntimeMain.java:14)
... 5 more
Caused by: org.eclipse.swt.SWTException: Invalid thread access
at org.eclipse.swt.SWT.error(Unknown Source)
at org.eclipse.swt.SWT.error(Unknown Source)
at org.eclipse.swt.SWT.error(Unknown Source)
at org.eclipse.swt.widgets.Display.error(Unknown Source)
at org.eclipse.swt.widgets.Display.createDisplay(Unknown Source)
at org.eclipse.swt.widgets.Display.create(Unknown Source)
at org.eclipse.swt.graphics.Device.<init>(Unknown Source)
at org.eclipse.swt.widgets.Display.<init>(Unknown Source)
at org.eclipse.swt.widgets.Display.<init>(Unknown Source)
at org.eclipse.swt.widgets.Display.getDefault(Unknown Source)
at org.eclipse.swt.widgets.Display$1.run(Unknown Source)
at org.eclipse.swt.graphics.Device.getDevice(Unknown Source)
at org.eclipse.swt.graphics.Resource.<init>(Unknown Source)
at org.eclipse.swt.graphics.Cursor.<init>(Unknown Source)
at org.eclipse.draw2d.Cursors.<clinit>(Cursors.java:170)
... 16 more
我已经检查了许多相关的线程:(无法在Mac OS X上获得SWT显示,在Mac上使用SWT的问题)以及SWT FAQ和教程中的UI线程条目,例如将Java应用程序带到Mac和在Mac OSX上部署SWT应用程序。
我的理解是,问题源于Mac OSX上的线程处理,我应该尝试在执行时实现JVM参数。这是对的吗?-XstartOnFirstThread
假设我对这个问题的理解是准确的,我有点困惑,因为这个软件是跨平台的,并在javaws上运行。我是否需要创建一个文件,如果是这样,在包中的位置以及如何创建,否则我如何在执行时“有条件地”将该参数传递给JVM?info.plist
提前致谢,