Retired Document
Important: This document may not represent best practices for current development. Links to downloads and other resources may no longer be valid.
Developing a Tool
This chapter shows how to develop text-based Java applications or tools in Project Builder using the tool project template. It guides you through the creation of two projects, Hello and Clock. The former one is a “Hello, World” application, while the latter is a simple tool to display the current time, which is included in this document’s companion files. See Introduction to Project Builder for Java for details.
Creating the “Hello, World” Tool
The Java Tool project template provides the prototypical “Hello, World” application. Follow these steps to create your first Java application using Project Builder.
Launch Project Builder. It’s located in
/Developer/Applications
.Create a Java tool project.
Choose File > New Project, and select Java Tool under Java in the project-template list of the New Project pane.
Name the project and choose a location for it.
In the New Java Tool pane of the Assistant, enter
Hello
in the Project Name text input field, click Choose, and choose a location for it.
When done, you should see the Project Builder window. Figure 3-1 shows the window with three editor panes, one for each file in the project, the Java source file, the manifest file, and the man page documentation file. The product, Hello.jar
, is shown in red because it hasn’t been built.

Build and run the application by choosing Build > Build and Run. Figure 3-2 shows the Run pane of the Project Builder window. The Run pane displays the console output of the application.

Creating the Clock Tool
This section shows how to create the Clock tool. Clock is a text-based application that tells time. It takes an optional command-line argument, the name of the user. You can find the finished product among this document’s companion files in companion/projects/Clock
(see Introduction to Project Builder for Java for details on companion files).
Follow these instructions to create the Clock tool.
Create a Java tool project and name it
Clock
.Edit the
main
method of the Clock class so that it looks like this:public static void main (String args[]) {
Date date = new Date();
if (args.length > 0) {
String user_name = args[0];
System.out.println("Hello, " + user_name + ". It's " + date);
}
else {
System.out.println("It's " + date);
}
}
Add an argument to the application’s launch arguments to test it within Project Builder.
Click the Targets tab to display the Targets list.
Click java under Executables in the Targets list.
Click the plus sign (+) in the Arguments pane of the target editor.
Enter
-jar "Clock.jar" Sheilla
in the newly added row of the Launch Arguments list.Deselect the Use option in the first row by clicking the checkmark in the Use column. The Arguments pane should now look like Figure 3-3.
Figure 3-3 Arguments pane of the executable editor in Project Builder
Build and run the application. You should see its output in Project Builder’s Run pane, as shown in Figure 3-4.

Installing the Clock Tool
This section shows how to install the Clock tool on a computer. Follow these steps to install Clock on your computer:
Determine the location of the installed product by adding the
INSTALL_DIR
build setting to the project and configuring the setting appropriately.Click the Targets tab to display the Targets list.
Click the Clock target.
Click Expert View under Settings in the target editor.
Click the plus sign (+) in the Build Settings pane.
In the newly added row, enter
INSTALL_PATH
in the Name column andTools
in the Value column. The Expert View pane should look like Figure 3-5.Figure 3-5 Expert View pane of the target editor in Project Builder
Run
pbxbuild
to install the application:Launch Terminal. It’s located in
/Applications/Utilities
.Execute the following commands:
% cd <path_to_Clock_project>
% pbxbuild install -buildstyle Deployment
Now, your /tmp
directory contains the Clock distribution directory (Clock.dst
), as shown in Figure 3-6.
/tmp

If you want pbxbuild
to install in the final destination of a product instead of in /tmp
, use the following commands:
sudo pbxbuild clean |
sudo pbxbuild install -buildstyle Deployment DSTROOT=/ |
This creates /Tools
in your root volume if it doesn’t already exist and places the application’s JAR file there, as shown in Figure 3-7.

To run the application, double-click the JAR file. To view the application’s output when you launch it from the Finder, launch Console, located in /Applications/Utilities
. Figure 3-8 shows Console displaying the output of a Clock session.

Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-10-10