Java Mac OS X App Bundle Machinations

Lost 6 hours of my life tracking down this issue, and of course in the end it turns out to be my user error, although as always as a developer you challenge whether it needed to be this hard to debug.

Objective

What was I trying to achieve was to create mac app bundle to put in a dmg to distribute my java desktop app. In Eclipse, generated a Mac app bundle using the export task.

9

Into Finder, double clicked the app and nothing happens. A quick search around Console, shows:

87

 

A quick google makes suggestions like there’s no main entry point defined in the jar file

5

This however is a rat-hole, there is indeed no main entry point defined in the manifest but a few more searches reveal the package isn’t invoked using java -jar xx.jar, it’s invoked using java -cp xx.jar mainEntryPoint. So we check the Info.plist in the app bundle, and find the main class is defined. So what’s going wrong?

This article http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/packagingAppsForMac.html seems to imply  a tool is needed at Java 7, so yep, great but why wouldn’t that be in eclipse already, i.e. why would eclipse claim to produce an app bundle if it did it the wrong way? Is it?  Time to go build one manually and see.

Manually creating an App Bundle, Java 7 (1.7.0_45-b18), Mac OS X 10.9.2

Downloaded appbundler-1.0.jar from https://java.net/projects/appbundler/downloads, as described in the Oracle article above and put it in a test directory.4

Set up the build.xml file from the various entries on the java.net and Oracle articles referenced above and running ant causes a no such file exception. It’s looking for an Info.plist file to be in the build directory. Odd, this isn’t mentioned anywhere!

3

Helpful: http://supunmali-myexperience.blogspot.co.uk/2012/10/jar-bundler-mac-os-x.html, resolved by setting JAVA_HOME but then I hit another problem:

1

If you’re not an experience Ant user (and I am not!), what this means is I forgot a target statement in the build.xml file, here’s the file I used at this stage which worked ….. or so I thought, it certainly allowed Ant to build the app bundle.

<?xml version="1.0" encoding="UTF-8"?>
<project name="DrumScore" default="default" basedir=".">

  <property environment="env"/>

  <taskdef name="bundleapp"
      classname="com.oracle.appbundler.AppBundlerTask"
      classpath="appBundler-1.0.jar"/>

  <target name="default">
    <bundleapp outputdirectory="."
        name="Drum Score Editor"
        displayname="Drum Score Editor"
        identifier="org.whiteware.DrumScoreEditor"
        shortversion="1.96"
        mainclassname="org/whiteware/DrumScoreEditor/main">
      <runtime dir="${env.JAVA_HOME}"/>
      <classpath
          file="${user.home}/Development/export/DrumScoreEditor-beta1.96.jar"/>
    </bundleapp>
   </target>
 </project>

And this gave me:

10

Frustratingly, trying to launch the generated .app bundle, I got exactly the same errors. What was going on here? I checked the Mac OS X Gatekeeper security level, it’s set to allow apps downloaded from anywhere so this should work!

Solution

There are many articles on various things which cause the 10810 error, from process table full to permissions and missing libraries.

What a huge diversion all these ratholes are you can go down. This is all so sketchy, returning errors meaning “unknown error”, meaningless “return code 1” in the syslog.

Bottom line is: do not try and follow the examples, work stuff out. Mine was failing because ……. I had assumed the main method name needed specific in the mainclassname statement, as is shown in the Oracle example. As soon as I made it the class name, and not the method it worked. i.e.

<?xml version="1.0" encoding="UTF-8"?>
<project name="DrumScore" default="default" basedir=".">

  <property environment="env"/>

  <taskdef name="bundleapp"
      classname="com.oracle.appbundler.AppBundlerTask"
      classpath="appBundler-1.0.jar"/>

  <target name="default">
    <bundleapp outputdirectory="."
        name="Drum Score Editor"
        displayname="Drum Score Editor"
        identifier="org.whiteware.DrumScoreEditor"
        shortversion="1.96"
        mainclassname="org/whiteware/DrumScoreEditor">
      <classpath
          file="${user.home}/Development/export/DrumScoreEditor-beta1.96.jar"/>
    </bundleapp>
   </target>
 </project>

Should I post this? After all it was my error in specifying it wrongly. Yes, because if anyone else is searching for answers in this murky, poorly documented space, made messy by Apple divorcing Java without a properly focused handing of the baton to Oracle….. this might just help!

I’m now scared … Mac, Sandbox, App Store: And the world just got infinitely more complicated …. http://www.intransitione.com/blog/take-java-to-app-store/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s