homeresourcesGuidesMac OSBundle java apps

italian

Bundle java applications in a “.app”
Often multiplatform java applications (just like Eclipse) are shipped in a folder containing a lot of stuff and the app, which merely is a launcher for the real application.
It’s easy to bundle everything in a single “.app”, just like a regular Mac application. Let’s see how…

In this example I’m going to use just Eclipse, “eclipse-java-helios-SR2-macosx-cocoa-x86_64”.

Download the application

Just download it with a simple click.
Don’t worry about saving it in .tgz, let Safari to expand it automatically, or in alternative just double-click it do expand the gzip.
Starting from tgz format possibly we’ll obtain a “.tar”, in this case double click it again and expand it, too.

Download the application

Keep expanded folder, trash everything else

Once everything has been expanded keep “eclipse” folder, and trash everything else (the ”.tar“ archive, and possibly the original “.tgz” unless automatically expanded).

Keep expanded folder, trash everything else

Make a copy of the “.app”

Move eclipse folder in some temporary folder, then copy the enclosed “Eclipse.app” application at the same level of the folder itself.
The application is very small, for it’s just a launcher, in our case it’s about 90KB.

Right click (or Control-click) the copy, and Show Package Contents.

Make a copy of the “.app”

Move original folder in Package Contents

Move original “eclipse” folder in “Contents” folder, within the package.

Open a Terminal window, type “cd ” (don’t forget the trailing space), and drag in Terminal text area the “MacOS” folder.
Focus again the Terminal (i.e.: with a click on title bar), type Enter.
We just made a “cd” on “MacOS” folder.

Move original folder in Package Contents

The magic...

Considering that at Finder level we can’t make the trick, we’re going to shuffle just a bit at Unix level.
At Unix level when “Eclipse.app” is launched this triggers the execution of unix executable “Contents/MacOS/eclipse”, and we’re going to replace it::
$ rm eclipse
$ ln -s ../eclipse/Eclipse.app/Contents/MacOS/eclipse

The magic...

It’s over!

Close the package window, the sole icon in our folder is “Eclipse.app”, containing the whole “eclipse” folder structure.

We can move it elsewhere, like in Applications folder, and simply double-click it.

It’s also possible to zip it or create a compressed “.dmg” image, to redistribute the bundled application.




This page was crated on 20 April 2011
Author: Marco Balestra