Deploy Java applications on Mac

September 25th, 2009 by ThierryWasyl Leave a reply »

Hello everyone,

It’s always fun to develop applications, but when it comes to deploy it, it can be a little bit tricky. OK, You could say to me “Java is great. You just have to deploy it using an executable Jar file or even using JNLP”. I agree and disagree. I like that my application looks like professional one. And when You’re on a Mac, You would like it’s like every Mac application : an application package. So we’ll see how to deploy Your applications as common Mac applications.

Step 1 : Some requirements

You will need to install XCode on Your Mac. You could find it on the given website, or on You Mac OS X Installation Disc.
There is two useful applications : Icon Composer (allows You to create ICNS File, i.e. icon files) and Jar Bundler (package Your Java application as Mac application).

Step 2 : Gather all needed files

We’ll suppose I already deploy my Java application as a Jar file named MyApp.jar. This application needs an XML file called config.xml which has to be in the same folder that the Jar is.

Step 3 : Create Your application’s icon

Every software has an icon, so why not yours? Create Your icon and save it as a PNG (just for the transparency, it’s cool). I recommend a size of 512×512 pixels, which is the maximum size of an icon on Mac OS X.
Then, start Icon Composer. Drag Your png file on the big square, and then to the smaller ones. It should looks like that :

iconcomposer

Just save Your icon as an ICNS file.

Step 4 : Bundle it

So last step (or almost the last one). Start Jar Bundler. Now, for the main class, just choose Your Jar file. The main class will automatically found. For me, I choose MyApp.jar. Choose Your brand new icon as well. Feel free to give more informations.
Ok, should look like this :

jarbundler_01

The go to the next tab, "Classpath and Files". Remember we said the application needs a XML file. Click on the "Add …" button in the section "Additional Files and Ressources" and choose the files the application needs. It should looks like this :

jarbundler_02

And finally go to the "Properties" tab. Give all information You want. It is very useful to check "Set Working Directory to Inside Application Package". Indeed, if Your application reads the config file, if You don’t check this, Your application will search the file where Your application package is… Commonly in the Apllications folder. Well that’s wrong because Your config file is inside the package… After that, it should looks like this :

jarbundler_03

Now, just hit "Create Applications…". It’s done !!

Step 5 : Where’s my SplashScreen ?!

OK guys. Nowadays, lot of applications use splash screen. And since 1.6, Java provides that. But I encounter a problem : in the manifest file of MyApp.jar, I put the instruction for the splash screen. But, when my application was packaged, it doesn’t appear !!
I found a solution. Right click on Your packaged application (MyApp.app) and click on "Show Package Content" and go in the Contents folder. Well edit the Info.plist file with Properties List Editor (available with XCode). In the node "Java" add a child named "SplashFile" and for the value enter something like this : $JAVAROOT/splash.jpg. The splash image is called splash.jpg is in the same folder that the Jar file in your packaged application. So You could add it as Additional Files and Resources (step 4). The Info.plist file should look like this :

info.plist

Well that’s it. Now You know how to deploy Your application on a Mac.
Enjoy.

Advertisement

Leave a Reply