Creating and managing projects
To develop programs in the JBuilder environment, you must first create a project.
JBuilder's integrated project management features allow you to create and manage projects. The AppBrowser provides the work space in which you perform most project management tasks.
This chapter explains what a project is and how to manage the projects you create in JBuilder. This chapter covers the following topics:
- What is a project?
Describes a JBuilder project, lists the types of files JBuilder automatically recognizes in a project, and explains how to display a project.
- Setting project properties
Describes project properties and explains how to set them.
- How JBuilder constructs paths
Explains how JBuilder constructs the Source Path, Out Path, Class Path, and Browse Path.
- Where are my files?
Explains where JBuilder finds the files it needs as you drill down into source code, compile your programs, and run and debug your programs.
- Packages
Explains packages and describes package names and naming conventions.
- Creating a new project
Explains how to create a project with the Project Wizard and describes how to import an existing file into a project.
- Opening an existing project
Explains how to open an existing project.
- Managing projects with the AppBrowser
Describes how to use the AppBrowser to manage your projects. Explains how to use the Project Browser
, project folders,
and the Opened Files Browser for project management
- Working with files
Discusses file management tasks, such as creating files, adding and removing files and classes to and from projects, opening files outside of projects, and adding packages to projects.
- Working with multiple projects
Describes how to manage more than one project at a time.
What is a project?
In its simplest form, a project is a holder of files. Generally, a project is used to "hold" the files that make up a JBuilder application or applet. These files can be in any directory.
The information about each JBuilder project is stored in a project file that has a .jpr file extension. This project file contains a list of all the files in the project and the project properties. JBuilder uses the information in the project file when you load, save, or build a project. You don't edit a project file directly; it is modified whenever you use the JBuilder development environment to add and remove files and set project options. You can see the project file as a node at the top of the Project Browser in the Navigation pane of the AppBrowser.
While you can include any type of file in a JBuilder project, these are the types of files that JBuilder automatically recognizes and has an appropriate view for.
File types in a JBuilder project
|
File types |
Description |
|
.jpr |
JBuilder project file. |
.java |
Java source file. |
.class |
Compiled class file. There is one for each class in a .java source file. |
.gif |
Graphics file. |
.jpg |
Graphics file. |
.bmp |
Graphics file. |
.au |
Sound file. |
.wav |
Sound file. |
.html |
HTML document. |
.txt |
Text file. |
.bat |
Batch file. |
.idl |
Interface definition language file. |
.sql |
Structured query language file. |
|
Displaying a project
JBuilder displays each project within its own AppBrowser. Therefore, if you have more than one project open, JBuilder opens an AppBrowser for each. To switch to another project during a JBuilder session, use the View|Windows command.
The following figure shows a new project file with a .jpr extension. The project contains three source files. These files are represented as nodes in the Project Browser.
To view the popup menu that applies to projects, select the project file (the .jpr file) in the Navigation pane and right-click. See the Navigation pane popup menu help topic for more information.
Setting project properties
Project properties control how the project is compiled, including the following:
- What version of the JDK is used to compile and run against.
- Where the compiler searches for files and places files.
- What Java libraries are used.
To set project properties,
- Right-click the .jpr file in the Navigation pane and choose Properties. You can also choose File|Project Properties.
The Project Properties dialog box is displayed.
- Click the Paths tab to display the the Paths page.
- Choose the following options:
|
Option |
Description |
|
Target JDK Version |
The version of the JavaSoft Java Development Kit (JDK) to use when compiling and running. JBuilder can compile and run against JavaSoft JDK versions 1.0 through 1.2 beta. To set up the list of available JDKs, click the Define button to display the Available JDK Versions dialog.
Note: The Debugger must always use the JDK that JBuilder runs in.
|
Source Root Directory |
The path the compiler searches for a source file. This is the root of the Source Path; subdirectories below the root represent the package structure. To add additional paths, separate them with a semicolon: ;Path 1;Path2 |
Output Root Directory |
The path in which the compiler places the .class files. This is the Out Path. Files are placed in a directory tree that is based on the package structure. To add additional paths, separate them with a semicolon: ;Path 1;Path2 |
Java Libraries |
The Java libraries to use when compiling. Libraries are searched in the order listed. To add another library to the list, click the Add button. To remove a library, click the Remove button. To switch the order of libraries, drag and drop them.
To change the list of available libraries, choose the Libraries button to display the Available Java Libraries dialog.
|
|
Note:
To set default properties for new projects, use the Default Project Properties dialog (Tools|Default Project Properties). To set global project properties that take effect immediately, use the Environment Options dialog (Tools|IDE Options).
How JBuilder constructs paths
The JBuilder IDE uses four paths during processing:
Paths are set at a project level. To set paths, use the Project Properties dialog box. See the topic called Setting project properties for more information.
In the construction of paths, JBuilder eliminates duplicate path names. This prevents potential problems with DOS limits.
Source Path
The Source Path controls where the compiler looks for source files. The Source Path is constructed from both of the following:
- The path defined in the Source Root Directory edit box on the Paths page of the Project Properties dialog box.
- The
Generated Source
directory. This directory contains source files that are automatically generated by the IDE. Examples of these source files include IDL server and skeleton files. The Generated Source
directory is placed in the Out Path.
The complete source path looks like this:
Source Path + Out Path\Generated Source
Out Path
The Out Path contains the .class files created by JBuilder. The Out Path is constructed from the path defined in the Output Root Directory edit box on the Paths page of the Project Properties dialog box.
Files are placed in a directory tree that matches the arrangement of the path specified in the Source Root Directory. If the Output Root Directory for the specified directory tree does not yet exist, it is automatically created. There is only one Out Path per project.
Class Path
The Class Path is used during a compile. This path is constructed from all of the following.
- The Out Path.
- The Class Path for each library listed in the Libraries list on the Paths page of the Project Properties dialog.
- The JDK version defined in the Target JDK edit box on the Paths page.
Note:
Library class paths are placed in the order libraries are listed in the Libraries list on the Paths page. Library class paths are defined in the Available Java Libraries dialog, opened by clicking the Libraries button on the Paths page.
The complete Class Path looks like this:
Out Path + Library class paths (in the order libraries are listed)+ JDK target version
Browse Path
The Browse Path is used by the IDE when you use:
- Browse Symbol at Cursor
- Search|Browse Symbol
- Debugger
The Browse Path is constructed from all of the following:
- The Source Path.
- The Source Path for each library listed in the Libraries list on the Paths page of the Project Properties dialog.
- The JDK version defined in the Target JDK edit box on the Paths page.
Note:
Library source paths are placed in the order libraries are listed in the Libraries list on the Paths page. Library source paths are defined in the Available Java Libraries dialog, opened by clicking the Libraries button on the Paths page.
The complete Browse Path looks like this:
Source Path + Library source paths (in the order libraries are listed)+ JDK target version
Where are my files?
Each file in a project is stored with a relative path to the location of the .jpr file, or an explicit path if necessary. JBuilder uses the Source Path, Class Path, and Out Path to find and save files.
- The Source Path controls where the compiler looks for source files.
- The Class Path is used during a compile.
- The Out Path contains the .class files created by JBuilder.
For information on how JBuilder constructs paths, see the section called How JBuilder constructs paths in this chapter.
How JBuilder finds files when you drill down
When you drill down to explore source code, JBuilder searches for the .java files using the Browse Path. By default, the file that holds the Java libraries, src.zip, is included in the Browse Path.
For more information about drilling down, see Drilling down into other classes and interfaces in "The JBuilder Environment" chapter.
How JBuilder finds files when you compile
When you compile your project, JBuilder uses the following paths:
- Class Path
- Source Path
- Out Path
JBuilder looks in the Class Path to find the location of the .class files, the libraries to use, and the target JDK version to compile against. The compiler compares the .class files with their source files, located in the Source Path, and determines if the .class files need to be recompiled to bring them up to date. The resulting .class files are placed in the specified Out Path.
For more information about compiling files, see the chapter called "Compiling Java programs" in Building Applications with JBuilder.
How JBuilder finds class files when you run or debug
When you run your program, JBuilder uses the Out Path to find classes your source code created, and it uses the Class Path to locate other classes your program uses.
When you debug your program, it uses the Browse Path to find files as you step through code.
Packages
Java groups .java and .class files in a package. All the files that make up the source for a Java package are in one directory; all compiled files are in another directory. The package can encompass both directories. A package is much like a library of source files (.java files) and classes (.class files). The name of the package always matches some portion of the far end of the directory name in which the .class or .java files are found.
As you create your programs, you will want to create your own packages to hold related sources and classes. For example, you might have a set of classes for drawing figures and within them some classes related to creating animal figures. The individual classes could include a Dog.class, Cat.class, Horse.class and so on. You could group all of the figure classes together in a figure package and further group the animals in a figure.animal package. Since a package always refers to a directory, the animal figure files would be stored in a directory path where the last two directories were figure\animal.
Source Root + Package Path = .java file location
It is important to understand what pieces of information JBuilder uses to build the directory location for any given .java file. The first part of the directory path is determined by the Source Path. The Source Path is the "root" to which JBuilder adds package paths to create the directory structure for the .java files used in your Java projects. The Source Path is defined at the project level and can been modified on the Paths page of the Project Properties dialog box.
The second part of the directory path is determined by the package name. On a directory level, the package name is just the rest of the path after the Source Path up to the source file name. For example, if the Source Path is C:\JBuilder\myprojects
, the package name for the file C:\JBuilder\myprojects\figure\animal\Cat.java
is figure.animal.
As shown above, the JBuilder nomenclature uses periods to separate the parts of a package. Use backslashes to get the directory path for the package.
Out Path + Package Path = .class file location
The directory location for the .class file is determined by the Out Path and the package name. The Out Path is the "root" from which JBuilder will add package paths to create the directory structure for the .class files generated by the compiler. The Out Path is defined at the project level and can been modified on the Paths page of the Project Properties dialog box.
The second part of the directory path is determined by the package name. Continuing with the example above, if the Out Path is C:\JBuilder\myClasses
, the compiled .class file for Cat.java in the package figure.animal would be placed in C:\JBuilder\myClasses\figure\animal\Cat.class
.
Using packages in JBuilder
When using classes from another package, your code will often use an import statement such as:
import figure.animal.*;
You seldom need to enter an import statement directly into your source code, as JBuilder's designers and wizards can add these statements for you automatically. You can reference a particular class in your code with its fully qualifying class name (that is: package name + class name without the extension). For example:
On the other hand, if the import statement above (import figure.animal.*
) was included in your source code, the reference to the Cat class would be just Cat instead of figure.animal.Cat. Importing packages isn't essential, but it is a convenient shortcut because it allows you to omit the package name when your code references a particular class.
Fore more information about packages, refer to one of the many excellent third-party sources for more information about packages and the Java language.
Package naming conventions
The following package naming conventions are recommended for use in all Java programs. In order to encourage consistency in readability and maintainability:
- Package names should be one word (for example, figure, animal, model).
- Package names should be singular (for example, figure vs. figures and animal vs. animals).
- Package names should be all lower case (for example, figure vs. Figure or FIGURE).
- If a package name must be more than one word, it should still be all lower case (for example, fourwordpackagename vs. FourWordPackageName).
If your packages will be used in a networked environment, package names should start with an Internet domain name, only reversed. For example, if you were using the domain name myDomain.com, your package names should be prefixed with com.myDomain.
Creating a new project
JBuilder gives you several ways for starting a new project. The method you choose to begin a project depends on what your goal.
You might want to start a new project by creating only the project file and adding files later. Or, if you intend to design an application or applet, you can use one of JBuilder's wizards to automatically generate the necessary framework. The wizard automatically generates a project file and imports the basic files if no other project is already open.
Choose one of the following topics for more information:
Creating a new project with the Project Wizard
Use the Project Wizard to create a new project. The Project Wizard automatically sets up the framework for the project and gives you the opportunity to enter informative data about the project such as its location on disk, the author of the project, and a description.
The Application and Applet Wizards both have a shortcut to the Project Wizard. If either one of those wizards is launched when there is no project open, the Project Wizard will be launched first so that you can create the new project. Then, control returns to the Application or Applet Wizard. The new application or applet will automatically be added to the newly created project. Note that the Application and Applet Wizards can be run at any time during the development of a project and the appropriate files will be added to the project.
To create a new project with the Project Wizard,
- Choose File|New Project.
The Project Wizard is displayed.
- Enter the name of the project file. Make sure the file extension is .jpr. You can edit the default path.
- Fill in the title, author, company, and description fields. These fields are optional.
- Click Finish when you're done.
The new project is dipslayed in its own AppBrowser. The project node is displayed at the top of the Navigation pane.
Creating a new project without using the Project Wizard
To create a project without using the Project Wizard,
- Choose File|Open/Create.
The Open/Create dialog box appears.
- Select the File tab, set the file type to Java Projects, and enter a file name (make sure it has the extension .jpr).
- Choose OK.
The new project is dipslayed in its own AppBrowser. The project node is displayed at the top of the Navigation pane.
Importing an existing file
To import an existing file into the newly created project,
- Choose the Add to Project button
at the top of the Navigation pane.
The Open/Create dialog box appears.
- Select the File tab and set the file type to match the file you wish to import.
- Navigate to the directory that contains the file to be imported.
- Highlight the file.
- Choose Open.
Opening an existing project
There are three ways to open an existing project. You can either use the File|Open/Create dialog box, the File|Reopen menu command, or the Directory Browser.
To open a project using the File|Open/Create dialog box,
- Choose File|Open/Create to display the File Open/Create dialog box.
- In the Files of Type box, select Java Projects to display only JBuilder project files.
- Navigate to the directory that contains the file to be imported.
- Select the .jpr file you want to open.
- Choose Open.
To open a project with the File|Reopen command,
- Choose File|Reopen.
A list of previously opened projects is displayed.
- Choose the project you want to open and press Enter.
To open a project using the Directory Browser,
- Choose the Directory tab.
The Directory Browser appears in the AppBrowser.
- In the Directory Browser, double-click directories to navigate to the directory that holds the project you want to open.
- Double-click the project file.
An AppBrowser appears, displaying the new project node in the Project Browser. If you have opened more than one project, each project appears in its own AppBrowser.
Managing projects with the AppBrowser
The AppBrowser enables you to perform project management tasks such as the following:
- See all files in a project.
- Open and edit files.
- Add source files and packages to a project.
- Add project folders.
- Navigate through directories.
- Drag and drop files from a directory into a project.
- Browse HTML files and Web graphics.
- Maintain a convenient list of opened and edited files.
- Drill down into the structure of classes, methods, and code elements.
The AppBrowser shows the Project Browser, the Opened Files Browser, or the Directory Browser in the Navigation pane, depending on which tab is selected at the bottom of the window. These trees enable you to navigate through a hierarchy or list of files and select a file.
When you select a file in any of the tree views, the file is presented in the relevant panes of the AppBrowser: the Source pane (for editing), the View pane (for HTML browsing), or the Structure pane (for navigating through methods or HTML headings). When you select a Web graphic file, JBuilder displays the image in the Viewer pane.
See also:
"The JBuilder Environment": Using the AppBrowser
Using the Project Browser to manage projects
The Project Browser, displayed in the Navigation pane, enables you to select a file in the current project. The Project Browser shows only the files and packages that are included in the project. The location of a file in the Project Browser does not necessarily match the placement of the file in a directory. A node of the Project Browser can be a file or package.
You can drag-and-drop a file from the Directory Browser or from the Windows Explorer onto the Opened tab to add the file to the Opened Files Browser without adding it to the project. See the topic called Using the Opened Files Browser in project management for more information.
Adding project folders
You can use project folders in your project to organize your project in a hierarchical structure. Project folders are for organizational purposes only.
To add a project folder to a project,
- Right-click the project file in the Navigation pane.
- Choose Add Folder.
The Add Folder dialog box is displayed.
- Enter the name of the folder.
- The folder is displayed in the Project Browser.
To add a file to a folder,
- Right-click the folder.
- Choose Add to Folder.
The File Open/Create dialog is displayed.
- Navigate to the directory and locate the file you want to add to the folder.
- Click OK.
To remove a file from a folder,
- Right-click the file,
- Choose Remove from Folder.
- The file is removed from the folder and from the project.
To remove a folder,
- Right-click the folder.
- Choose Remove Folder.
The folder is removed from the project.
Using the Opened Files Browser in project management
The Opened Files Browser keeps track of all the files you opened or edited. These files do not have to be a part of your current project. The list of opened and edited files can contain files that you want access to while working on a project. It provides a convenient, termporary workspace in which to gather files that might be spread across several directories.
For example, if you want to modify the source code of an independent package in another directory, you can put the package file in the Opened Files Browser so you can have easy access to it. If you later decide to add the package to the current project, you can drag the package icon from the Opened Files Browser onto the Project tab.
The Opened Files Browser, like the Project and Directory Browsers, enables you to select various types of files that then appear in the panes relevant to that file type.
To view the Opened Files Browser, click the Opened tab. The browser appears in the Navigation pane.
The Opened Files Browser is created automatically when you open or edit files. You can also drag and drop files from the directory or Project Browser onto the Opened tab; these are added to the list of files even if they haven't been opened yet.
Using the Directory Browser to manage projects
The Directory Browser enables you to:
- View and navigate through local and network directories.
- Open files in any directory.
- View HTML files in the Content pane.
- Choose text files and see their content in the Content pane.
- Open files whose content you wish to edit in the Content pane.
- Drag and drop files from any directory to a project or Opened Files Browser.
To display the Directory Browser,
- Choose the Directory tab, located at the bottom of the Structure pane.
- The Directory Browser appears in the Navigation pane.
The Directory Browser provides an easy way for you to find and add files to your JBuilder projects.
To add a file to a JBuilder project using the Directory Browser,
- Choose the Directory tab.
- Navigate to the directory and locate the file you want to add to your project.
- Select the file and drag and drop it onto the Project tab.
To add a file to the Opened Files Browser using the Directory Browser,
- Choose the Directory tab.
- Navigate to the directory and locate the file you want to add to the list of opened files.
- Select the file and drag and drop it onto the Opened tab.
To remove the Directory tab from the AppBrowser, right-click it and choose Drop Directory tab.
To view the Directory tab again, right-click the Project or Opened tab and choose View Directory tab.
Working with files
This section describes how to work with files within a JBuilder project. Choose one of the following topics for more information:
Creating a new file
JBuilder enables you to create files and add them to an open project in a single step. Or you can create a new file, save it to a directory, and use it later.
To create a new file,
- Choose File|Open/Create or click the Add To Project button
at the top of the Navigation pane.
The File Open/Create dialog appears.
- If you want to immediately add the file to the current project, check the Add To Project check box. If you want to save the file to a directory, select a directory from the drop-down list.
- Name the file.
- Choose Open.
The file is created, and a node for the file appears in the Project Browser if you checked the Add To Project check box.
To add text to the file, click the file node and enter text in the Source pane.
If you do not already have an AppBrowser open when you create a file, an AppBrowser appears, showing the new file in the Project Browser. The Source pane is empty. You can type text in the Source pane, such as the code for a new class.
After you edit a file, save it by using File|Save or pressing Ctrl+S. The path and directory in which the file is saved appears on the status bar at the top of the AppBrowser.
Adding existing files to a project
You can add an existing file to a project by dragging and dropping it or by using the File Open/Create dialog box.
To add a file using drag and drop,
- Click the Directory tab.
- Locate the file you want to add to the project using the Directory Browser.
- Drag the file from the Directory Browser and drop it onto the Project tab.
You can also locate files using the Windows Explorer and drag and drop them onto the Project tab.
To drag and drop files from one AppBrowser to another,
- Select the file you want to add within another project's AppBrowser.
- Drop the file on the Opened tab, or onto the Project tab of another AppBrowser.
To add a file using the File Open/Create dialog box,
- Choose File|Open/Create or choose the Add to Project button
at the top of the Navigation pane.
The File Open/Create dialog box is displayed.
- Select a file or specify a new file name in the dialog box.
- Check the Add To Project check box.
- Choose Open.
The file is added to the Project Browser. If you don't check the Add To Project check box, the file is not added to the project, but is added to the Opened Files Browser nstead.
Adding a Java class to a project
To add a Java class to a project,
- Choose File|Open/Create or choose the Add to Project button
at the top of the Navigation pane.
The File Open/Create dialog box is displayed.
- Choose the Packages tab.
- Choose the Class (Fully Qualified Name) option.
- Navigate to the desired class file.
- Choose OK.
The class is added to the Project Browser. If you don't check the Add to Project check box, the class file is not added to the project, but is added to the Opened Files Browser.
Adding a package to a project
To add, or import, a package to a project,
- Choose File|Project Properties.
The Project page of the Properties dialog box appears.
- Choose File|Open/Create or click the Add to Project button
at the top of the Navigation pane.
The File Open/Create dialog box is displayed.
- Choose the Packages tab.
- Choose the Package option.
The list of available packages appears.
- Select the package to add.
- Check the Add to Project check box.
- Choose OK.
Removing a file from a project
To remove a file or package from a project,
- Click the Project tab in the AppBrowser, and select the file in the Project Browser.
- Click the Remove From Project button
at the top of the Navigation pane or choose File|Remove From Project.
The file is now deleted from the project and is removed from the Project Browser.
Opening a file outside of a project
Occasionally you might want to open a file, but you don't want to add it to a project. You can use the File|Open/Create command or you can find the file want to open in the Opened Files Browser and double-click it.
To open a file without adding it to a project,
- Choose File|Open/Create.
- Select the file you want to open.
- Leave the Add to Project check box unchecked.
- Choose Open.
The file is added to the Opened Files Browser and is displayed in the Content pane of the AppBrowser. If the file is a text file, the Source tab is selected and you can edit the file. If the file is a graphics file, the Viewer tab is selected and you can view the file but not edit it.
Working with multiple projects
You can work on multiple projects simultaneously in the JBuilder development environment. Each project appears in its own AppBrowser.
To see a list of all open projects, choose View|Windows.
This section describes how to work with multiple projects. Choose one of the following topics for more information:
Switching between projects
To switch between projects, select the View|Windows command. Choose the project you want to switch to.
Editing a file in another project that is closed
When you have one AppBrowser open, you can modify files in another project without opening that project.
To modify a file in another project that is closed,
- Select the Directory tab at the bottom of the AppBrowser.
- Navigate to the directory containing the file you want to modify and double-click the file.
The source code for the file appears in the Source pane.
- Edit the code and save your changes.
- Select the Project tab to return to the current, open project.
Saving multiple projects
To save changes to all open files and projects, choose File|Save All.
Closing multiple projects
To close all open files and projects, choose File|Close All.