Pages

Tuesday, March 10, 2015

Packaging Java applications for Mac OS, javapackager

Stumbled upon an issue with installing muCommander on Mac. The native installer did not work, saying that the launcher is corrupted, but the portable version worked just fine via the command line:
java -jar mucommander.jar

Launching a GUI app from the command line is not convenient at all. One option is to assemble the *.app package using Launch4j. However, I didn't have enough patience to do apply the tool. So I tried looking for an alternative solution.
So I found this guide: Packaging a Java App for Distribution on a Mac. And the instructions worked just fine! Here's what I did:
1. Downloaded the appbundler utility from https://java.net/downloads/appbundler/
2. Create a build.xml file. For instance:
3. Run "bundle" task: ant bundle
Profit! :)
This is all cool and works, but the process is a bit clumsy. One has to download some strange utility and use a legacy build tool to assemble the final artifact. We should do better! So I found another documentation page: Java Platform, Standard Edition Deployment Guide: Self-Contained Application Packaging. Apparently, there's a javapackager utility included in JDK distribution that you can use to create native packages.
By running the following command in the same folder where mucommander.jar is located, it created the desired artefacts:
$JAVA_HOME/bin/javapackager -deploy -native -outdir .  -outfile mu.app \
-srcfiles mucommander.jar -appclass com.mucommander.Launcher -name "muCommander" \
-title "muCommander"
Voila!
muCommander-0_9_0 anton$ ls -l bundles/
total 269904
-rw-r--r--@ 1 anton  staff  75110066 Mar 10 23:53 muCommander-1.0.dmg
-rw-r--r--  1 anton  staff  63076596 Mar 10 23:53 muCommander-1.0.pkg
drwxr-xr-x  3 anton  staff       102 Mar 10 23:53 muCommander.app
The only missing bit there is a proper icon, which I was too lazy to bother about :)

No comments:

Disqus for Code Impossible