Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-swt-dev] FW: Running SWT on Mac OSX

Hi,

I am playing around with writing an SWT application as a comparison to
Swing/AWT.  I am trying out my application on different platforms, one of
which is Mac OSX.

I can bring up my user interface on the mac, but have no access to the
interface.  I cannot select the window or activate menu options, etc.

Any clues?

Yes, this is a known problem with Java-based UI applications on Mac OS X.
It was one the bigger problems I had to solve in the Mac port of Eclipse.

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 that problem because they seem to use not documented
SPI to register themselves. (I asked on various Apple mailing lists but I got
only (unofficial) answers that confirmed my theory, but doesn't name the SPI).

My workaround is to wrap the Java application as a standard 'packaged' application, or a so called 'application bundle'. (It is the same that ProjectBuilder does when
running a Java application). Part of the package is a small (40k)
Apple provided Java launcher that does the initialization.

Eclipse contains a script that takes the normal Java command line
(your "java -cp ../lib/demo.jar:../3rdparty/sw.....") and builds a packaged
application from it. This happens automatically when running Java from Eclipse.
So the easiest way for you would be to run your application once from within
Eclipse. You don't have to build the command line from below yourself, just
don't forget to specify the -Djava.library.path in the Launch Configuration
wizard. After running the application once, you'll find the script in /tmp
as "start_carbon.sh" and your packaged application in "/tmp/swt_stubs" as
some subfolder <app_name>.app. The script should allow you to run your
application just by passing the original command line to the script.
And if you open the directory /tmp/swt_stubs in the Finder with "open /tmp/swt_stubs"
you should be able to launch your application by double clicking.

The command I am using to start the application:

java -cp ../lib/demo.jar:../3rdparty/swt-macosx.jar
-Djava.library.path=../native/os/macosx/ppc
com.wickidcool.banking.swt.BankDisplay

I am using the swt.jar (renamed to swt-macosx.jar) and native libraries from
the M1 release.  I have also tried the a couple of the later builds...

They should work when using the above recipe.

Let me know if it works.
--andre


Back to the top