We have a few different examples packaged up in JPedal that can be started by setting system properties with the -D flag from the command line. I thought it would be interesting to get these to run in the same way as you expect other programs to run with installers, continue buttons and all that good stuff. In this article I’m going to package up JPedal with a view to run the ContentExtractor example.
If you want the ContentExtractor to run from the command line you type java -jar -Dorg.jpedal.ContentExtractor jpedal.jar. The JVM then knows to call the main method in that class as opposed to the one specified in the jars manifest. I’m going to get it to run as a Mac package.
All the tools to help me achieve this come with XCode so I installed it on a Mac. It comes with a set of tools that can package up your jar and create an installer for you. I also need a copy of JPedal trial jar. It will need an icon as well (its got to be a PNG and 128 by 128 pixels).
To make the icon I used the Icon Composer application. Its in /Developer/Applications/Utilities. When you open it your see a bunch of windows representing different icon sizes. One of them is the 128 by 128 box so you drop the icon in there. Then save it and you have a ICNS file that you can use and your done with the Icon Composer.
Next you use the Jar Bundler app to make your Mac application. That is in /Developer/Applications/Java Tools (This might not work, I installed XCode 4 and got an exception when I tried to run it. If this happens to you there is another version in /usr/share/java/Tools and this one worked for me.) Next to the Main Class field click the choose button and select the jar you wish to use. It automatically points to the default main class. I don’t want to use the default one so I change it to point to the Content Extractor: org.jpedal.examples.contentextractor.ContentExtractor. I choose my ICNS file with the Choose Icon button.
If you go to the Properties tab you can set the memory usage in the appropriate fields (I used 512 and 1024 equivalent to using the command line arguments -Xms512 and Xmx1024) and also pass arguments in the VM options field if you want. Put in a version number and put it into the Get-Info String as well so Finder will display it with the Get Info option in the context menu. Then you can click Create Application and give it its name and your done with the Jar Bundler.
Now you Jar is a Mac app. Exciting eh? Another Mac app can help you make an installer. You want the PackageMaker app thats lives in /Developer/Applications/Utilities. Run it and it will ask for your organisation (ie com.idrsolutions) and a Minimum Target OS version. OK that and drag and drop your app in to the contents window.
Then head to the components tab and deselect Allow Relocation. This option says that if the installer is run again it will search for the app in all possible locations so it may replace it somewhere other than the destination set in the Configuration tab. This is useful for a User but not a developer with a couple of copies of their app on their system, the desired one may not be changed in that case.
Give it a name in the Title field in the Configuration tab. Go to the Contents tab, check that include root in package is selected and click Apply Recommendations. Now you can click the Build button and ta-da, you have an installer and can really look like you know what your doing! Zip it up and your ready to send it out to your nearest and dearest…
Latest posts by Daniel (see all)
- Custom HTML Font Mapping in PDF to HTML conversion - July 30, 2011
- Turn a Jar in to a Mac app complete with Installer - June 13, 2011
- JAI Memory Leak Source Changes - April 28, 2011
- Java JAI image-io jpeg2000 Memory Leak fix - March 24, 2011
- Java images – What is happening with JAI? - March 22, 2011