Wednesday, December 10, 2008

Understand Projects

Understanding Projects

An Eclipse project is a set of Java files that together build a single Java program. Although some simple Java programs consist of just one file, most real-world Java programs are made up of more than one Java program file. In fact, a complicated Java program may require hundreds of Java program files. When you work on programs that require more than one file, Eclipse lets you treat those files together as a project.

A project consists not just of Java source files, but also the class files that are created when you compile the project and any other files that the program requires. That might include data files or configuration files, as well as other files such as readme files, program documentation, image files, sound files, and so on.

All the files for a project are stored together in a project folder, which may include subfolders if necessary. In addition to the files required by the program, the project folder also includes files that are created by Eclipse to store information about the project itself. For example, a file named .project stores descriptive information about the project, and a file named .classpath stores the locations of the classes used by the project.

All your project folders are stored in a folder called the workspace. Each time you start Eclipse, a dialog box appears asking for the location of the workspace folder. If you want to change to a different workspace, use File Image from book Switch Workspace.

Eclipse lets you create two types of projects:

  • For simple projects that have just a few Java source files, you can create a project that stores all the project's Java files in a single folder. Then, when those files are compiled, the resulting class files are stored in this same folder. This type of project is the easiest to work with, and it's ideal for small and medium-size projects.

  • For large projects-those that involve dozens or even hundreds of Java source files-you can create a project that uses one or more subfolders to store source files. You are then free to create whatever subfolders you want to help you organize your files. For example, you might create one subfolder for user interface classes, another for database access classes, and a third for image files displayed by the application.


Tip

Eclipse has a File Image from book Open File command, but this command isn't very useful. Instead, the Package Explorer View (on the left side of the Java perspective; refer to Figure 4-1) displays a list of all the Java projects in your workspace. When you start Eclipse, the project you were last working on appears on-screen automatically. You can switch to a different project by right-clicking the project in the Package Explorer, and then choosing Open Project. And you can open an individual file in a project by double-clicking the file in the Package Explorer.

No comments:

Post a Comment