If our software is open source, we can do even better and
propose restoring changed files to their standard versions. For
class files specifically, this means we have to recompile the Java
files. Of course, your users have to have the whole JDK (not just a
Java runtime) and your source code and the build file for your source
code. To restore the changed class files, we delete them and call
the compilation task of the installation build file. The specifics
of this task depend on your build system.

As an alternative (for example, if your software is closed
source), you could put known-good versions of the class files in a
.jar or .zip in a safe location and unpack them. You can then
replace the changed class files with their known-good versions.

On the other hand, configuration files can be copied from the
source directory. In order to do this, we extend the target
configChanged appropriately and add a target
configRestore:

If the configuration file has been changed, Ant asks the user if
he wants to back up the configuration file and restore the original.
If he answers "yes" by pressing Y and Enter, the
property config.copy is set. The target
configRestore will only be executed when this property
is set, backing up build/config.xml to
build/config.xml.1 and copying the original
src/config.xml to build/config.xml.

Conclusion

We developed an Ant script to run diagnostic tests for a Java
application. The script checks whether the version of the Java
installation meets a minimum requirement, if some important files
haven't been changed, if a specific Java class is in the class path, if a
directory exists, etc. After checking all of these prerequisites of
the software, the script reports the results to the user. The script can even repair
some problems. In addition, the output of the diagnostic
test can be used by technical support to help the user quickly,
without asking him a whole list of questions.