Brad Lucas

A blog mostly about programming
June 21, 2006

Pattern For Laying Out Cvs Trees For Java Projects

Once you start working with others on larger Java projects you will require a logical CVS tree to store and share project artifacts among each of the team members.

With this it should go without saying that you need to start designing your applications with a sound package structure.

These two activities can conflict due to the nature of how each project contains Java sources in a directory structure to match the package structure. To make this clear start two Java projects that contain sources for the com.mycompany.database project. If you do this you’ll see that there isn’t a way to prevent collisions in names because each project is using the same package name.

Solution

To work around this I came up with a simple scheme.

First, you pick your root directory in your CVS tree. For a large company this might be a few levels down. For smaller you might want to start with $CVSROOT/java.

This root directory will contain all of your Java projects. Also, this directory will match up with com.mycompany. This will be come clearer later.

Next, create a couple projects as examples, say Example1 and Example2. In these projects create a package structure for each that matches the project as a sub-package under com.mycompany.

In other words, Example1 will have a src directory that looks like src/com/mycompany/example1 and Example2 will have a src directory that looks like src/com/mycompany/example2.

Save each project in CVS under $CVSROOT/java using the project name. When complete you should have two directories, $CVSROOT/java/Example1 and $CVSROOT/java/Example2.

Note, that a project name will be capitalized and will show up as such in CVS. Also, a project name will become a lower-case package name under the ‘root’ package of com.mycompany if the project is stored directly under $CVSROOT/java.

So far so good. Now, suppose things are going well and you want to create a set of projects under a deeper package structure. For example, suppose you are going to have a set of database projects.

First, you start a new sub-directory in CVS, $CVSROOT/java/database. In this you’ll create your new projects. Remember projects will be capitalized. The lower case database tells someone that it is only a sub-directory, not a project and as a result not meant to be checked out.

Now, you start a couple database projects. You’ll now from above that now your package structure will be one level lower so DatabaseExample1 and DatabaseExample2 will have the following src directories.

src/com/mycompany/database/databaseexample1 and

src/com/mycompany/database/databaseexample2

To summarize

Layout your CVS tree to imply your package structure to projects. Capitalize projects when stored in CVS to mark them as projects. Use sub-directories, left lowercase to show that projects are to be developed with matching sub-projects.

Setup your CVS tree to have an implied root for Java projects and assume that all projects created at that level will use the package structure of com.mycompany for the root and the project name, lower-cased as the sub-package.


Tags: cvs java