简体   繁体   English

Eclipse:导出项目,以便Windows和Mac都可以运行它

[英]Eclipse: export project such that Windows and Mac can both run it

I just finished coding a new Java application, and I would like to export it to a format that can be read on both Windows and Mac (or, if needed, two separate formats). 我刚刚完成了对新Java应用程序的编码,我想将其导出为可以在Windows和Mac上读取的格式(或者,如果需要,可以使用两种单独的格式)。 I tried right-clicking on my project and exporting to a runnable JAR file, choosing to extract the required libraries into the generated JAR. 我尝试右键单击项目并导出到可运行的JAR文件,然后选择将所需的库提取到生成的JAR中。

Since I've never exported from Eclipse before (I'm used to Unity and, to a lesser extent, Visual Studio), I'm sure I did something wrong, as it would not open on either macOS Sierra or Windows 10. What did I do wrong? 由于我以前从未从Eclipse导出过(我习惯于Unity,从某种程度上来说,它习惯于Visual Studio),所以我确定我做错了什么,因为它无法在macOS Sierra或Windows 10上打开。我做错了吗? Thanks! 谢谢!

EDIT: Here's the output when I try to run java -jar on the JAR (file name has been obfuscated): 编辑:这是当我尝试在JAR上运行java -jar (文件名被混淆)时的输出:

***WARNING: Display must be created on main thread due to Cocoa restrictions.
Exception in thread "main" org.eclipse.swt.SWTException: Invalid thread access
    at org.eclipse.swt.SWT.error(SWT.java:4533)
    at org.eclipse.swt.SWT.error(SWT.java:4448)
    at org.eclipse.swt.SWT.error(SWT.java:4419)
    at org.eclipse.swt.widgets.Display.error(Display.java:1089)
    at org.eclipse.swt.widgets.Display.createDisplay(Display.java:840)
    at org.eclipse.swt.widgets.Display.create(Display.java:823)
    at org.eclipse.swt.graphics.Device.<init>(Device.java:129)
    at org.eclipse.swt.widgets.Display.<init>(Display.java:722)
    at org.eclipse.swt.widgets.Display.<init>(Display.java:713)
    at org.eclipse.swt.widgets.Display.getDefault(Display.java:1419)
    at myJar.MainWindow.main(MainWindow.java:19)

You appear to be running a SWT application. 您似乎正在运行SWT应用程序。 On macOS you must specify the -XstartOnFirstThread option when running the jar to run SWT correctly: 在macOS上,运行jar才能正确运行SWT时必须指定-XstartOnFirstThread选项:

jar -XstartOnFirstThread -jar xxxx.jar

SWT applications also have a native library which is different for each platform. SWT应用程序还具有一个本机库,该库对于每个平台都不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM