Bei dem Versuch unter Mac OS mit Eclipse ein Runnable JAR File zu exportieren bin ich heute auf ein Problem gestossen. Der Export an sich klappt problemlos, doch wenn man das JAR dann gestartet hat – eine SWT Applikation – war die Applikation langsam bis hin zur Unbrauchbarkeit.
Da dieses Problem nicht auftritt wenn die Applikation aus Eclipse heraus gestartet wird, habe ich im Terminal ein wenig mit ps gespielt und herausgefunden, dass Eclipse per default die folgenden Java Option setzt -XstartOnFirstThread. Startet man das Runnable JAR direkt (per Doppelklick) fehlt diese Option.
Dieses Problem wird auch im SWT FAQ behandelt, aber das habe ich erst hinterher gefunden ;):
Q: On Mac Carbon, how do I run an SWT application from the command line?
A: If you run a Java application that uses Carbon via JNI, the application is not registered with the OS as a ‘normal’ UI application. As a consequence, it has no entry in the dock and it cannot be activated. AWT (or Swing) based applications don’t have this problem because they seem to use undocumented SPI to register themselves.
To work around this problem you’ll have to pass the -XstartOnFirstThread option to the java executable as follows:java -XstartOnFirstThread -cp swt.jar:. ControlExample
If you want to run a bundled application, take a look at this article.
Zum Glück führt das FAQ dann auch direkt zu diesem Artikel, der beschreibt wie man aus einem Runnable JAR ein Mac OS Bundle machen kann. Das ist genau die Information, die mir noch gefehlt hat und das werde ich natürlich vorm Release von iPlode noch ausprobieren und dann berichten; ich hoffe vielmehr man kann das Ergebnis dann hier bewundern :).
