Using Maven to create a Mac OS X app bundle

I came across this post and this Maven plugin today. Call me cynical, but I was shocked when it worked out of the box, building our application as a Mac friendly .app which can be run with a double click.

To test it out, all I did was change into our application’s trunk directory and ran:

mvn package osxappbundle:bundle -DmainClass=com.mypkg.MyMain

And it worked!

So I extended integrated it into our pom.xml with the following. Now whenever our app is packaged on a Mac, in addition to the other artifacts, an .app, .dmg, and .zip of the My App tool will be created.

<profiles>
   ....
        <profile>
            <id>package-osx-bundle</id>
            <activation>
                <os>
                    <family>mac</family>
                </os>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>osxappbundle-maven-plugin</artifactId>
                        <configuration>
                            <mainClass>com.mypkg.MyMain</mainClass>
                            <bundleName>My App</bundleName>
                            <jvmVersion>1.5+</jvmVersion>
                        </configuration>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <!-- append to the packaging phase. -->
                                <goals>
                                    <goal>bundle</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

About Josh

Josh is a software architect and engineer with a fine arts background. You can connect with him on Google+.
This entry was posted in Tech and tagged , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>