<?xml version="1.0"?>
<rss version="2.0">
<channel>
  <title>simplericity - mac tag</title>
  <link>http://simplericity.com/tags/mac/</link>
  <description>Reducing software entropy</description>
  <language>en</language>
  <copyright>Eirik Bjørsnøs</copyright>
  <lastBuildDate>Fri, 02 Jan 2009 11:02:56 GMT</lastBuildDate>
  <generator>Pebble (http://pebble.sourceforge.net)</generator>
  <docs>http://backend.userland.com/rss</docs>
  
  
  <item>
    <title>Packaging Java apps for OS X with Maven</title>
    <link>http://simplericity.com/2007/09/19/1190234671861.html</link>
    
      
        <description>
          &lt;p&gt;Anyone attending a Java conference the past few years must have noticed the steady increase of Java developers working on a Mac. The good looking hardware sure helps, but the main reason people are flocking to the Mac is OS X.&lt;/p&gt;
&lt;p&gt; Apple&#039;s operating system is a great platform for Java developers since it combines the power of Unix with a UI that is actually possible to use. Installing an application is as easy as downloading it and dragging it to the Applications folder.&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt; But that&#039;s until you try to install Java software. Some projects are helpful and create double-clickable jars, others just reuse the scripts from their Linux distribution and force you to start Terminal just to lauch their app.&lt;/p&gt;
The reason for this is probably that &lt;a href=&#034;http://developer.apple.com/documentation/Java/Conceptual/Java14Development/03-JavaDeployment/JavaDeployment.html#//apple_ref/doc/uid/TP40001885-208447-TPXREF120&#034;&gt;hand-crafting Java application bundles&lt;/a&gt; for OS X is quite tedious. A while back I decided to do something about this sad state and make the Java world a better place to be for Mac people.&lt;br /&gt;
&lt;br /&gt;
What I did was to create a Maven plugin that will take any Maven project&amp;nbsp; and make it into a first class OS X application bundle.&lt;br /&gt;
&lt;br /&gt;
But first, a little motivational example to illustrate why you should care about this:&lt;br /&gt;
&lt;br /&gt;
My friend Sigurd has made this cool little Java app called &amp;quot;Hva&amp;quot; that helps you keep track of hours. Every now and then it will pop up and ask you what you&#039;ve done&amp;nbsp; since last time. &lt;br /&gt;
&lt;br /&gt;
&lt;img src=&#034;/images/hva/hva-example.png&#034; alt=&#034;&#034; /&gt;&lt;br /&gt;
&lt;br /&gt;
(For those of you who&#039;s Norwegian is a little rusty: &amp;quot;Hva&amp;quot; translates to &amp;quot;What&amp;quot; and this dialog asks what you&#039;ve been up to since 7:36 PM)&lt;br /&gt;
&lt;br /&gt;
Because Sigurd is one of these helpful guys, he distributes his app as a double-clickable jar file. &lt;br /&gt;
&lt;br /&gt;
Like any other application, I dragged the jar file to the Applications folder on my Mac and this is what it looks like:&lt;br /&gt;
&lt;br /&gt;
&lt;img width=&#034;384&#034; height=&#034;225&#034; alt=&#034;&#034; src=&#034;/images/hva/hva-applications.png&#034; /&gt;&lt;br /&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;This really isn&#039;t too bad, but there are some subtle things that tells me this is not a properly bundled OS X application. First &amp;quot;Hva?&amp;quot; is the only application that has a file name suffix (&amp;quot;.jar&amp;quot;) in it&#039;s name.&amp;nbsp; Second, the logo of the application is the generic and dull Java Application logo.&lt;/p&gt;
&lt;p&gt;So what can Sigurd do to give the users of Hva a better experience on the Mac?&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;Well, if he&#039;s using &lt;a href=&#034;http://maven.apache.org&#034;&gt;Maven&lt;/a&gt; (and he should!) there is no longer any excuse for giving his Mac users a bellow par experience of his application: &lt;/p&gt;
&lt;p&gt; Yesterday I released the &lt;a href=&#034;http://mojo.codehaus.org/osxappbundle-maven-plugin/index.html&#034;&gt;OS X Application Bundle Maven plugin&lt;/a&gt; which is a part of the &lt;a href=&#034;http://mojo.codehaus.org&#034;&gt;Mojo project&lt;/a&gt; over at &lt;a href=&#034;http://codehaus.org&#034;&gt;Codehaus&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt; All you need to give this plugin is&amp;nbsp; a main method to launch and it creates a beautiful OS X application bundle ready for clicking by your users.&lt;/p&gt;
&lt;p&gt;In order to use this plugin for Hva, Sigurd could add hva.jar to his Maven repository and create a Maven project with this pom.xml:&lt;/p&gt;
&lt;pre name=&#034;code&#034; class=&#034;java&#034;&gt;&amp;lt;project&amp;gt;&lt;br /&gt;  &amp;lt;modelVersion&amp;gt;4.0.0&amp;lt;/modelVersion&amp;gt;&lt;br /&gt;  &amp;lt;groupId&amp;gt;hva&amp;lt;/groupId&amp;gt;&lt;br /&gt;  &amp;lt;artifactId&amp;gt;hva-maven&amp;lt;/artifactId&amp;gt;&lt;br /&gt;  &amp;lt;version&amp;gt;1.0-SNAPSHOT&amp;lt;/version&amp;gt;&lt;br /&gt;  &amp;lt;name&amp;gt;hva&amp;lt;/name&amp;gt;&lt;br /&gt;  &amp;lt;dependencies&amp;gt;&lt;br /&gt;    &amp;lt;dependency&amp;gt;&lt;br /&gt;      &amp;lt;groupId&amp;gt;hva&amp;lt;/groupId&amp;gt;&lt;br /&gt;      &amp;lt;artifactId&amp;gt;hva&amp;lt;/artifactId&amp;gt;&lt;br /&gt;      &amp;lt;version&amp;gt;1.0&amp;lt;/version&amp;gt;&lt;br /&gt;    &amp;lt;/dependency&amp;gt;&lt;br /&gt;  &amp;lt;/dependencies&amp;gt;&lt;br /&gt;&amp;lt;/project&amp;gt; &lt;/pre&gt;
&lt;p&gt;  Then he needs to add the following plugin configuration:&lt;br /&gt;
&lt;/p&gt;
&lt;pre name=&#034;code&#034; class=&#034;java&#034;&gt;&amp;lt;plugin&amp;gt;&lt;br /&gt;    &amp;lt;groupId&amp;gt;org.codehaus.mojo&amp;lt;/groupId&amp;gt;&lt;br /&gt;    &amp;lt;artifactId&amp;gt;osxappbundle-maven-plugin&amp;lt;/artifactId&amp;gt;&lt;br /&gt;    &amp;lt;version&amp;gt;1.0-alpha-1&amp;lt;/version&amp;gt;&lt;br /&gt;    &amp;lt;configuration&amp;gt;&lt;br /&gt;        &amp;lt;mainClass&amp;gt;Hva&amp;lt;/mainClass&amp;gt;&lt;br /&gt;    &amp;lt;/configuration&amp;gt;&lt;br /&gt;    &amp;lt;executions&amp;gt;&lt;br /&gt;        &amp;lt;execution&amp;gt;&lt;br /&gt;            &amp;lt;goals&amp;gt;&lt;br /&gt;                &amp;lt;goal&amp;gt;bundle&amp;lt;/goal&amp;gt;&lt;br /&gt;            &amp;lt;/goals&amp;gt;&lt;br /&gt;        &amp;lt;/execution&amp;gt;&lt;br /&gt;    &amp;lt;/executions&amp;gt;&lt;br /&gt;&amp;lt;/plugin&amp;gt; &lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;Running mvn:install should now create an OS X application bundle in the project&#039;s&amp;nbsp; target directory:&lt;/p&gt;
&lt;img alt=&#034;&#034; src=&#034;/images/hva/hva-target.png&#034; /&gt;&lt;br /&gt;
&lt;p&gt;As you can see, the plugin has created an application bundle, plus packaged the application in both a zip and a disk image file ready for distribution. &lt;/p&gt;
&lt;p&gt;This is nice, but what if Sigurd wants to add a custom icon to Hva? First he needs to open the Icon Composer utility located in /Developer/Application/Utilities/Icon Composer:&lt;/p&gt;
&lt;img alt=&#034;&#034; src=&#034;/images/hva/hva-icns.png&#034; /&gt;&lt;br /&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Here, I&#039;ve created an icon in various sizes from the photo in my collection that looked most like the letter &amp;quot;H&amp;quot;. I&#039;ve stored this file as &amp;quot;hva.icns&amp;quot; in src/main/app-resources and used the iconFile property to tell the plugin where it can find the icon, like this:&lt;br /&gt;
&lt;/p&gt;
&lt;pre class=&#034;xml&#034; name=&#034;code&#034;&gt;&amp;lt;plugin&amp;gt;&lt;br /&gt;    &amp;lt;groupid&amp;gt;org.codehaus.mojo&amp;lt;/groupid&amp;gt;&lt;br /&gt;    &amp;lt;artifactid&amp;gt;osxappbundle-maven-plugin&amp;lt;/artifactid&amp;gt;&lt;br /&gt;    &amp;lt;version&amp;gt;1.0-alpha-1&amp;lt;/version&amp;gt;&lt;br /&gt;    &amp;lt;configuration&amp;gt;&lt;br /&gt;        &amp;lt;mainclass&amp;gt;Hva&amp;lt;/mainclass&amp;gt;&lt;br /&gt;        &amp;lt;iconFile&amp;gt;${basedir}/src/main/app-resources/hva.icns&amp;lt;/iconFile&amp;gt;&lt;br /&gt;    &amp;lt;/configuration&amp;gt;&lt;br /&gt;    &amp;lt;executions&amp;gt;&lt;br /&gt;        &amp;lt;execution&amp;gt;&lt;br /&gt;            &amp;lt;goals&amp;gt;&lt;br /&gt;                &amp;lt;goal&amp;gt;bundle&amp;lt;/goal&amp;gt;&lt;br /&gt;            &amp;lt;/goals&amp;gt;&lt;br /&gt;        &amp;lt;/execution&amp;gt;&lt;br /&gt;    &amp;lt;/executions&amp;gt;&lt;br /&gt;&amp;lt;/plugin&amp;gt;&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;After running mvn:install, our target/ directory now looks like this:&lt;/p&gt;
&lt;br /&gt;
&lt;p&gt;&lt;img src=&#034;/images/hva/hva-target-withicon.png&#034; alt=&#034;&#034; /&gt;&lt;/p&gt;
&lt;br /&gt;
&lt;p&gt;Let&#039;s rename it and move it to the Applications folder:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#034;http://simplericity.com/images/hva/hva-applications-withicon.png&#034; alt=&#034;&#034; /&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;Notice the neat icon on the application and how much smoother it looks in the Dock now:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#034;/images/hva/hva-dock-withicon.png&#034; alt=&#034;&#034; /&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;See the &lt;a href=&#034;http://mojo.codehaus.org/osxappbundle-maven-plugin/&#034;&gt;plugin&#039;s site&lt;/a&gt; for full documentation. The Maven example project I created for Hva can be found in the Simplericty Subversion repository, here:&lt;/p&gt;
&lt;p&gt;&lt;a href=&#034;http://simplericity.org/svn/simplericity/projects/hva-maven/&#034;&gt;http://simplericity.org/svn/simplericity/projects/hva-maven/&lt;/a&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;br /&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
        </description>
      
      
    
    
    
    <category>Java</category>
    
    <comments>http://simplericity.com/2007/09/19/1190234671861.html#comments</comments>
    <guid isPermaLink="true">http://simplericity.com/2007/09/19/1190234671861.html</guid>
    <pubDate>Wed, 19 Sep 2007 20:44:31 GMT</pubDate>
  </item>
  
  </channel>
</rss>
