Recipe 23.12


Recipe 23.12 "Write Once, Install on Mac OS X"

Problem

You want to install your Java program as a first-class application under Mac OS X.

Solution

Structure your build directory as shown here. Or use a tool such as a commercial installer (Recipe 23.11) or the Eclipse IDE Export Mac OS Application wizard.

Discussion

Mac OS X applications require a specific installation format, which is fairly easy to understand. Each Mac OS X Application, regardless of programming language, is installed in a separate directory called an " Application Bundle", whose name should end in ".app". This is the preferred way of installing applications under Mac OS X. Unlike simple JAR files, Application Bundles will be shown as icons in Finder ("explorer") windows and elsewhere, can be saved in the Dock for single-click startup, and can have file types associated with them (so that double-clicking or opening a file will launch your application and have it open the file).

Figure 23-7 shows a listing of the files in a simple Java application's directory.

Figure 23-7. Files in the Java application directory on Mac OS X
figs/jcb2_2307.gif


As you can see, there is one directory Contents with two subdirectories: MacOS and Resources. Contents/MacOS contains the executable program, in the Java case JavaApplicationStub, a native-language Java launcher for Mac OS (provided with the Developer Tools package). Contents/Resources/xxx.icns contains icons in various resolutions for display by the Finder; this file can be created using the IconComposer program (found in /Developer/Applications/Utilities/Icon Composer.app). The directory Contents/Resources/Java contains your Java classes and/or JAR files. Contents/Info.plist ties the whole thing together, specifying the names of the various files, the file types your application can open, and other information.

The better commercial installer tools (discussed in Recipe 23.11) generate this structure for you. You can create this structure using Ant. Eclipse 3.0 (since "Milestone 7") can generate a Mac OS X Application. Just select your Project in the Eclipse navigator, select Export Mac OS X application from the Export menu, and fill in two screens specifying the output destination and some other information, as shown in Figure 23-8. In the case of Ant or Eclipse, you probably want to use Disk Copy to build a dmg (disk image) file of your directory; dmg files can be downloaded by Mac OS X users and are normally expanded automatically upon download to recreate the Application Bundle.

Figure 23-8. Eclipse Application Bundle Export screen
figs/jcb2_2308.gif


See Also

Chapter 7 of the book Mac OS X for Java Geeks, by Will Iverson, covers Application Bundles. This book is recommended for any Java developer concerned with making good use of Java on OS X, and especially for anyone shipping applications who is concerned with making a good impression on OS X users.



Java Cookbook
Java Cookbook, Second Edition
ISBN: 0596007019
EAN: 2147483647
Year: 2003
Pages: 409
Authors: Ian F Darwin

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net