MrRizk
MrRizk

Reputation: 111

errors with SWT library once I try to export runnable jar from java program

Hi everyone I am trying to create runnable jar file using Eclipse I am using two external libraries the first one is SWT library and the second one is opencv the application is working great in eclipse but once I try to export the jar file I received warnings:

the warnings message

and I get the following errors once I tried to run the jar file using the terminals by this command:

java -jar <name>.jar

I received the following errors:

***WARNING: Display must be created on main thread due to Cocoa restrictions.
org.eclipse.swt.SWTException: Invalid thread access
at org.eclipse.swt.SWT.error(SWT.java:4491)
at org.eclipse.swt.SWT.error(SWT.java:4406)
at org.eclipse.swt.SWT.error(SWT.java:4377)
at org.eclipse.swt.widgets.Display.error(Display.java:1097)
at org.eclipse.swt.widgets.Display.createDisplay(Display.java:848)
at org.eclipse.swt.widgets.Display.create(Display.java:831)
at org.eclipse.swt.graphics.Device.<init>(Device.java:130)
at org.eclipse.swt.widgets.Display.<init>(Display.java:721)
at org.eclipse.swt.widgets.Display.<init>(Display.java:712)
at org.eclipse.swt.widgets.Display.getDefault(Display.java:1427)
at detectingApplication.gui_rec.<init>(gui_rec.java:42)
at detectingApplication.gui_rec.main(gui_rec.java:58)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)

Any suggestions?

Upvotes: 0

Views: 442

Answers (1)

greg-449
greg-449

Reputation: 111217

The 'Exported with compile warnings' messages mean some of your code does not compile cleanly. Eclipse should be showing you warnings about this (unless the warnings have been turned off).

When running on Mac OS X you must specify the -XstartOnFirstThread option on your java command to ensure the correct thread is used by SWT. This will fix the 'Display must be created on main thread due to Cocoa restrictions' error. This error is not related to the compile warnings messages.

Upvotes: 1

Related Questions