Diagnostic Tests with Ant

Suppose you have developed your Java application and distributed
it to your users. If all goes well, the application just works on
every computer. But if there's a problem, you have to begin
troubleshooting. Users will call for all sorts of installation
problems, expecting you to fix them. Moreover, the same problems
will often come back: the wrong version of Java, a deleted file,
too-restrictive file permissions, etc. Most of these problems can
be solved by creating a checklist. However, instead of wasting time
asking new users the same questions on the checklist over and over,
you can create a diagnostic test that goes through the checklist,
providing users with the information they need to solve the problem. If
users can't solve the problem themselves, they can show you a clear
checklist, so you can take a look at what's going wrong without
asking a bunch of questions first.

What problems can users expect? First, things can already go
wrong during the installation process if the user doesn't
follow the installation instructions accurately. Even if the
installation succeeds, problems can appear later. Changes in
configuration (like the JAVA_HOME environment
variable) or changes in the directory structure can indeed break
things. In this article, we will develop an Ant script to run diagnostic tests for
a Java application. We will look at a list of possible problems and
how to deal with them. For our approach to work, Ant has to be
installed on the user's machine. This may mean that your installer
will have to provide Ant.

System Configuration

The first thing you should know to troubleshoot is the system
configuration--the operating system, Java version, classpath,
etc. Implementing this is easy, because Ant provides access to all
Java system properties. Here's an example (reformatted for the
ONJava layout; each <echo> should be on one line):