Creating And Running Executable Jar Files


Creating Java Projects Using Macintosh OS X Developer Tools

The Macintosh OS X operating system is based on an open-source version of Berkeley BSD UNIX called Darwin. So, if you are a Linux user, or you are familiar with another version of UNIX, you will feel right at home on a Macintosh running OS X. However, if you don t know a thing about UNIX, you will still feel right at home on a Macintosh because that s the beauty of a Macintosh!

OS X ships with a complete set of software-development tools, including the Java SDK and JRE. If you choose to do Java development on the Macintosh, you will get upgrades to the Java SDK directly from Apple Computer.

Once you install the OS X developer tools, you are ready to start Java development. The Java command-line tools are automatically installed in the /usr/bin directory. Your PATH and CLASSPATH environment variables will already be set to use the Java SDK.

You can develop Java programs using either the Java command-line tools or the OS X Xcode IDE. Xcode is a full-featured IDE that enables you to create programs not only in Java but in C, C++, and Objective C as well.

Creating A Java Project With Xcode

Xcode, like any IDE, is project-centric. Thus, the first step to creating a Java program in Xcode is to create a Java project. When you start Xcode, create a new project by selecting the File > New Project menu. This launches the Xcode New Project Assistant, as is shown in figure 2-33.

image from book
Figure 2-33: Xcode New Project Assistant

For this example select, Java Tool in the Assistant window, and click the Next button. This will take you to the New Java Tool window as is shown in figure 2-34.

image from book
Figure 2-34: New Java Tool Window

Enter the name of the project in the Project Name field and use the Choose button to set or select the project directory. When you are finished with the New Java Tool window, click the Finish button. Xcode will automatically create both the project and a .java application source file bearing the project s name.

Edit the image from book ApplicationClass.java file to make it look like example 2.2. When finished, you will need to add the image from book SampleClass.java file. This is easy with Xcode: simply add a new Java class file to the project named SampleClass and edit it to look like example 2.1. Figure 2-35 shows the Xcode ApplicationClass project with both image from book ApplicationClass.java and image from book SampleClass.java files added.

image from book
Figure 2-35: Xcode ApplicationClass Project Window

Notice that figure 2-35 shows the presence of two additional project artifacts. Xcode, by default, creates a .jar file when it builds the project. (A .jar file is a Java Archive File and is similar to a zip file.) The manifest file is an important part of the .jar file, because it names the main application class. In this example, the manifest file needs to be edited to reflect the main application class s fully-qualified package name. Figure 2-36 shows the Manifest file being edited.

image from book
Figure 2-36: Editing the Manifest File to Reflect the Correct Package Location of the Main Application Class

After editing the manifest file, build and run the project by selecting the Build > Build and Run menu command. Figure 2-37 shows the ApplicationClass project running in the Xcode environment.

image from book
Figure 2-37: Running ApplicationClass Project from Xcode IDE

Quick Review

Macintosh OS X provides a complete suite of Java programming tools. These range from traditional UNIX text editors such as vi and emacs, to the full-featured IDE Xcode. The Java SDK comes with OS X. Updates to the SDK must be obtained directly from Apple.




Java For Artists(c) The Art, Philosophy, and Science of Object-Oriented Programming
Java For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
ISBN: 1932504052
EAN: 2147483647
Year: 2007
Pages: 452

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