Creating a Mac OS App Bundle with Maven Tycho


Using Maven Tycho it is possible to build OSGi applications and therefore Eclipse RCP applications easily with Maven. Creating a ready to run product is already described on the internet a few times.

But what is mostly missing is, how to make an nice Mac OS X application bundle, that looks like a real Mac OS X application and not like a bunch of files extracted from a ZIP/TAR file.

Assuming you already have set up your Maven Tycho RCP build and are building products using the packaging type “eclipse-repository” here is what you need to do in addition.

Extend the configuration in the “eclipse-repository” project by calling (or enhancing the call) to:

<plugin>
  <groupId>org.eclipse.tycho</groupId>
  <artifactId>tycho-p2-director-plugin</artifactId>
  <version>${tycho-version}</version>
</plugin>

If you don’t have a configuration element for this plugin yet, then add it as a child element and configure the specific product you are building:

<plugin>
  <groupId>org.eclipse.tycho</groupId>
  <artifactId>tycho-p2-director-plugin</artifactId>
  <version>${tycho-version}</version>
  <configuration>
    <formats>
      <win32>zip</win32>
      <linux>tar.gz</linux>
      <macosx>tar.gz</macosx>
    </formats>

    <products>
      <product>
        <id>${group.id}.${artifact.id}</id>
        <rootFolders>
          <macosx>My Application.app</macosx>
        </rootFolders>
      </product>
    </products>
  </configuration>
</plugin>

${group.id} and ${artifact.id} make up the id of your application. Which must be consistent with the id property in the .product file.

The most important thing is the configuration of the “rootFolder” for the target type Mac OS X here. It would also be possible to use the plain “rootFolder” property, but using “rootFolders” (with the “s”) it is possible to just make an alternate name for Mac OS X.

In addition to that tell the repository bundle (in the same Maven project) to generate for Mac OS X.

<plugin>
  <groupId>org.eclipse.tycho</groupId>
  <artifactId>tycho-p2-repository-plugin</artifactId>
  <version>${tycho-version}</version>
  <configuration>
    <includeAllDependencies>true</includeAllDependencies>
    <profileProperties>
      <macosx-bundled>true</macosx-bundled>
    </profileProperties>
  </configuration>
</plugin>

Running maven package will now give you a products folder under your output folder (normally target) which hosts a zipped version of your Mac OS X app bundle, which extracts to “My Application.app” and shows in the finder as “My Application”.