Create 'native' Java applications on OS X and Windows using Maven plugins

When building a desktop application, the target audience usually expects an executable to when launching it. If the application is written in Java you have the options to create a batch file to launch it, create an executable jar file, compile the application as a native application or wrap the application using a native ‘launcher’. This post will result in a maven pom for dealing with the last option, it may be used in both Windows and OS X environments.

The pom is configured to use two different plugins depending on which operating system that is executing it.
On Windows, a Launch4j project plugin will be used. On OS X the osxappbundle plugin is used, which creates an OS X application directory structure and uses the JavaApplicationStub binary for launching the application.

The <profile> tag is used for deciding which plugin to use depending on operating system.

The pom also points out different application icons for the binaries, OS X requires the icon to be in the icns and windows in the ico format.

The wrapped application has a main class in the file com.jayway.wrappedapplication.Launcher

The pom.xml

And that’s it.

This Post Has 2 Comments

  1. Thank you for pointing this out! This was very helpful for one of my projects.

  2. Just for the record: groupid and artifactid should have capitalized i’s in id, eg. artifactId

Leave a Reply

Close Menu