9
2005
Bundling SWT Apps for MacOSX
So you’ve written your killer SWT app and you’re keen to bundle it in a nice clickable Mac application bundle for distribution on OSX? Such has been my journey for last few days. I reckon I’ve sunk around 10 hours into just this process over the last week, but I now have it working. First, let me show show off: (it’s good therapy)
Ok, the resources that you need to read are:
- First, you need to read an awesome background article at Borderland Consulting
- Then, you’ll want the very cool Jar Bundler Ant Task which will put together an app bundle for you and copy all your jars into the right directory structure and create an Info.plist file for you
- Then (and this bit just killed me), you must make sure that you chmod your .jnilib files executable! If you don’t, you’ll end up getting a “Could not load library” error even though the swt library is clearly in your java.library.path!
-
Finally, you must add an entry
to your Info.plist file which resolved some Threading issues with the launcher. If you’re getting weird GUI behaviour with disappearing buttons and bizarre crashes, it will probably be cause you’ve missed this setting.StartOnMainThread
I’m a Mac newbie, so it took me a while to work out why my app would launch, bounce a few times in the dock, then die. You can find out why via the Console application (Applications/Utilities/Console) – which is where the errors get dumped from the lauching process. That’s when I worked out it couldn’t load the .jnilib files even though they were in java.library.path (since they weren’t chmoded executable).
The other thing that I couldn’t get working was using $JAVAROOT in an Info.plist setting for java.library.path. It would just never get expanded by the launcher. I ended up cutting my losses and just copying the my .jnilib files to the same directory as the rest of my jars.
BTW, I’ve been using the jars from Eclipse 3.1RC1 to get all this happening. Earlier jars required you to use a special java_swt launcher to fix those threading issues I was talking about, but the 3.1 stream just uses the standard JavaApplicationStub launcher which is just easier all round.
Eclipse 3.1 also has this “Export To… Mac App Bundle” option but it just tanked every time I tried it, so that might be one to sleep till the final release.
Have fun! Hopefully all this will save you some pain!
5 Comments + Add Comment
Leave a comment
Glen Smith
Archives
- January 2012
- November 2011
- October 2011
- September 2011
- August 2011
- July 2011
- June 2011
- April 2011
- March 2011
- January 2011
- November 2010
- October 2010
- September 2010
- August 2010
- July 2010
- June 2010
- May 2010
- April 2010
- February 2010
- January 2010
- December 2009
- November 2009
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006
- October 2006
- September 2006
- August 2006
- July 2006
- June 2006
- May 2006
- April 2006
- March 2006
- February 2006
- January 2006
- December 2005
- November 2005
- October 2005
- September 2005
- August 2005
- July 2005
- June 2005
- May 2005
- April 2005
- March 2005
- February 2005
- January 2005
- December 2004
- November 2004
- October 2004
- September 2004
- August 2004
- July 2004
- June 2004
- May 2004
- March 2004
- February 2004
- January 2004
- December 2003
- November 2003
- October 2003
- September 2003

An article by Glen





Does this somehow help the double dock icon? If the eclipse icon is already in the dock, clicking on it will create another icon.
AFAIK, this is just an SWT-ism.
I think the reason Eclipse gets two icons in the dock is something to do with an extra laucher thread is spawns to being able to reload itself in some circumstances (when you switch workspaces?). Anyways, that behaviour is an eclipse thing, not an SWT thing.
This certainly doesn’t affect your own SWT apps. When I launch PasswordSafeSWT from the Dock there is no “extra” icon. The select icon bounces, then runs.
Thanks so much for posting this info.
I’ve been curious about how to do exactly this.
Hi!
First of all, this post is very interesting! I am writing and Ans script do bundle the application and decided to also use the XMLTask (http://www.oopsconsultancy.com/software/xmltask) to add the key “StartOnMainThread” to the Info.plist file. After declaring the task definition, all I need is this:
You don’t need the “entity” tag, I just used in order to change it from Windows.
Hope it is useful.
Once again, congratulations for such a great article!
Nuno Fernandes.
Thanks for writing up all your efforts – it’s helped me a lot in creating my first ever Java application bundle!
I found that I could simplify things by putting the jnilib files into the MacOS folder using the nested execfileset element. This automatically sets its files to be executable and I think that the MacOS folder is a more appropriate place to put native dlls anyway. To get them added into the library path, you have to specify a javaproperty – you can’t use -Djava.library.path in the vmoptions!
To summarize, here’s my jarbundler task call:
<jarbundler dir="${dist.mac.dir}" name="${app.name}" mainclass="${main.class}" stubfile="${java.application.stub}" workingdirectory="$APP_PACKAGE/Contents/Resources" > <!-- Include the SWT native jnilibs --> <javaproperty name="java.library.path" value="$APP_PACKAGE/Contents/MacOS"/> <execfileset dir="${mac.dir}/dll"> <include name="*.*"/> </execfileset> <jarfileset dir="${mac.dir}"> <include name="*.jar"/> </jarfileset> <jarfileset file="${main.jar}"/> </jarbundler> <!-- Hack! Write the StartOnMainThread key into Info.plist in order to get SWT working on OS X. Info.plist will always contain a ClassPath key in the right place. --> <replace file="${dist.mac.dir}/${app.name}.app/Contents/Info.plist" token="<key>ClassPath" value="<key>StartOnMainThread</key><true/> <key>ClassPath" />I’ve also included your method for adding the StartOnMainThread key (taken from SWTSafe’s build.xml – thanks for that tip!