CI Tools and Best Practices in the Cloud

Continuous Integration

Subscribe to Continuous Integration: eMailAlertsEmail Alerts newslettersWeekly Newsletters
Get Continuous Integration: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn


Continuous Integration Authors: Elizabeth White, Pat Romanski, Yeshim Deniz, Liz McMillan, Mehdi Daoudi

Related Topics: Java EE Journal, Java Developer Magazine, Continuous Integration

J2EE Journal: Article

Setting Up a Java Shop: How To Build Better Software Faster

Basic infrastructure: Utility Classes, Standards and Conventions, Build and Quality Control Tools

Regardless of which approach you subscribe to, consider incorporating default exception handlers into your architecture. The ThreadGroup class has an uncaughtException method that you can use to apply default processing for exceptions that propagate up from any threads in the ThreadGroup. With JDK 1.5, things get even better, as the Thread class has a setUncaughtExceptionHandler method that sets the handler for the thread, and a setDefaultUncaughtExceptionHandler method that sets the exception handler for all threads that don't have their own exception handler.

Shop Layout, Standards, and Procedures
Don't try to reinvent the wheel when it comes to deciding how to organize your project directories and defining development standards, guidelines, and conventions - there are plenty of resources on the Web to which you can refer.

Sun has published directory and naming standards at http://java.sun.com/blueprints/code/projectconventions.html and http://java.sun.com/blueprints/code/namingconventions.html, which should be your preferred starting point unless other considerations are overriding. One such consideration might be your selection of a build tool - for example, Maven (discussed below) has a recommended directory structure.

Sun also has published coding standards, although I find the Sun standards to be rather excessive and prefer fewer standards, with more focus on reducing potential sources of problems. In that light I recommend starting with the AmbySoft standards at www.ambysoft.com/javaCodingStandards.html, which also discuss alternative approaches for various items such as parameter naming.

Ant is the de facto standard for building Java applications, but it isn't just for building, as it supports almost all development tasks short of writing code and project management. In addition, many product manufacturers such as application server vendors now provide Ant code for building with, configuring, deploying to, and/or managing their products.

You can incorporate Ant into an automated build and test environment using CruiseControl. The advantages of doing so are explored in Martin Fowler's discussion of Continuous Integration (available from the CruiseControl Web page), and come from the observation that the earlier in the development process you find problems, the cheaper it is to fix them. Continuous Integration helps you find many problems soon after they are inserted into the baseline.

You can also have CruiseControl automatically run various open source tools (discussed below) that identify potential bugs and quality issues in your code. These tools, along with Ant, can log their processing steps and results as XML, which means that their execution can be automatically analyzed and acted upon. For example, CruiseControl can analyze build results and send e-mail reporting on the success or failure of the build and automated tests.

An alternative to the combination of Ant and CruiseControl is Maven, which provides a more comprehensive, project-management perspective. I haven't used Maven and so can't comment on it, but their Web site contains extensive documentation.

Quality Control and Improvement
You can improve the efficiency of your development effort and the quality of your product by incorporating automated tests using JUnit and tools built on top of it such as HttpUnit and Canoo WebTest. HttpUnit provides APIs that you can call to simulate requests from a browser, whereas with WebTest (which uses HttpUnit) you write XML to do the same.

As mentioned earlier, a number of open source products exist to improve the quality of your code. FindBugs and PMD analyze your code to identify possible bugs, including sins such as the previously mentioned consumption of exceptions. JDepend helps you manage dependencies between Java packages, because it's easier to extend, reuse, and maintain packages if the dependencies between packages are well factored. JavaNCSS counts lines of code, number of classes, etc., and also computes cyclomatic complexity numbers (a.k.a. McCabe metrics), which can be used to identify code that is overly complex and should be considered for refactoring.

Most (if not all) of these tools provide Ant targets and plugins for IDEs such as Eclipse. So in addition to running tools such as these as part of your build cycle, you should ensure that developers know about them and routinely run them against their code before checking it in.

Summary
These elements of a project infrastructure are low-hanging fruit - a modest investment of effort to incorporate them into your development efforts early on will provide benefits throughout development, helping you build better software faster.

More Stories By Glen Cordrey

Glen Cordrey is an architect and developer of J2ME and J2EE applications. He works in the Washington, D.C. area and has been working with Java for six years.

Comments (1) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
Sid Sidner 08/18/05 01:44:56 PM EDT

Glen,

This article was terrific - one of the best that I've read in JDJ. While I was familiar with some of these ideas, others were new. Thanks a bunch. I can really use this.

- Sid

*************************
Sid Sidner
Master Engineer
*************************