Code and Stuff

Feb 24, 2012

Eclipse RCP Mac OS App Export Tricks

Exporting an Eclipse RCP application for Mac OS X produces a result that is not very Mac like:
  1. The user settings should be saved in the Library path.
  2. An application on Mac should be a single .app package. No other folders should be needed.

The user setting

Let me start with the simple one. What we actually want to do is to place the worspace inside the Library folder. This can be done in the eclipse product configuration by setting the following program launching argument for the MacOS:
-data
@user.home/Library/YourAppName
This will use ~/Library/YourAppName as the default location for the workspace.

Making the App

Unfortunately, AFAIK, Eclipse is not capable of generating the single App thing. There has been an open bug for quite a while now and there seems to be no interest to address this problem. In the mean time there is a quite simple solution.
  1. Export the product the usual way. You will end up with the folder containing the .app, plugins, etc.
  2. Open the folder containing the generated stuff with finder, right click the .app file and select "Show Package Contents".
  3. Move everything except the app itself into the "Contents/Resources" folder of the package.
  4. Open the .ini file in "Contents/MacOS" with a text editor and update the -startup and --launcher.library paths replacing ../../../ with ../Resources/

And that should be it.

This applies to eclipse 3.7.1 and was not tested extensively. Please see the comment of Scott Barrett if the app cannot find the library.

Eclipse.app

Since Eclipse RCP applications and the Eclipse IDE are based on the same technologies this tricks should apply also to the IDE.

2 comments:

Scott Barrett said...

Thanks so much for your instructions on how to pick up Eclipse's slack. I'm using Eclipse 3.7.2 and found that modifying the .ini in "Contents/MacOS" per step 4 of your instructions had no effect. Upon launching, the app would complain that the product's "executable launcher was unable to locate its companion shared library."

The necessary magic is to edit the "Contents/Info.plist" file, adding entries to the array value of the "Eclipse" key:

<key>Eclipse</key>
    <array>
        ...
        <string>--launcher.library</string>
        <string>../Resources/plugins/org.eclipse.equinox.launcher.cocoa.macosx.x86_64_1.1.101.v20120109-1504/eclipse_1408.so</string>
        <string>-startup</string>
        <string>../Resources/plugins/org.eclipse.equinox.launcher_1.2.0.v20110502.jar</string>
    </array>

where the --launcher.library value provides the path to the eclipse_*.so file within the highest-versioned org.eclipse.equinox.launcher.{platform} folder and the -startup value provides the path to the highest-versioned org.eclipse.equinox.launcher jar file.

It sure would be nice if Eclipse could do this correctly in the first place!

Thanks again for your informative post.

- Scott

satreth said...

Thanks for the fix.

I tried with Eclipse 3.7.2 (64bit, new download not upgrade) on my OSX Snow Leopard and, strangely, it worked without the change to the plist file.