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, you 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 an ICNS file that you can use and you are 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 you are 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 that 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 into 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 a 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 you are doing! Zip it up and you are ready to send it out to your nearest and dearest…
Do you need to solve any of these problems in Java?
Convert PDF to HTML5
Convert PDF to SVG
View Forms in the browser
View PDF Documents
Convert PDF to image
Extract Text from PDF
Convert Image to PDF