3. Development Tools

Directory Structure for Development and Deployment

Author: Scott Franson

Objective: Discussion of proper directory structure with thought to deployment.


A Digression on Project Directory Structure

Nota bene: like the discussion on the Eclipse IDE, this discussion is largely obsolete because Eclipse (and NetBeans) imposes (though not absolutely) a directory structure upon the web application. It used to be confusing and difficult to follow these best practices, but now there is little reason even to concern yourself with them as they are implemented automatically for you.


Before we get to Eclipse and the other development tools, we take a brief detour and discuss current “best practices” in relation to the directory structure of J2EE projects. Over the years, the experience of J2EE developers has coalesced to expect a specific directory structure for projects. Developers expect to put and find files in a specific directory structure when they come onto a project. While this may seem unreasonable to some, it does help developers come up to speed quickly when joining a project.

By analogy, consider Windows. There are specific directories where you expect to find different types of files: the c:\windows directory contains operating system files; the c:\Program Files directory is where program executables and resources are installed; and user specific data is stored under the user's directory under c:\Documents and Settings. While not explicitly required to do so, an application does well to follow this structure because it plays along with the basic assumptions that users have about their computers; it allows them to find things quickly and backup their data by copying only one directory instead of dozens.

The current “best practices” for J2EE projects use the following directory structure:

/                   - root directory of project
+- src/             - all project source files are under the src directory
|  +- main/         - all source files relating to the application itself
|  |  +- java/      - all of the application's java source files
|  |  |  +- ...     - any other structure needed for java source files
|  |  +- resources/ - application resource files that are copied directly into the package
|  |     +- ...     - any other structure needed for application resources
|  +- test/         - all unit tests to test the application
|  |  +- java/      - java unit tests
|  |  |  +- ...
|  |  +- resources/ - resources needed only by the tests themselves; not delivered in the package
|  |     +- ...
|  +- site/                     
|     +- xdoc/
|        +- ...
+- target/          - the 'build' directory; where all generated code is put
|  +- classes/      - directory for compiled Java classes
|  +- ...
+- project.xml      - the build file for the project
+- README.txt       - other descriptive files relating to the project
+- LICENSE.txt

Though not required by any of the development tools, projects that follow such standard directory structures free the developer from the time and attention that project-specific structures would require.


Links


Assignment

(assignment)