Using a Diagnostic

The JDiagnose diagnostics are designed to be useable in as many environments as possible. The simplest would be directly from Java code. To run the JavaVersionDiagnostic you could use the following snippet:

JavaVersionDiagnostic diagnostic = new JavaVersionDiagnostic("1.3+");
DiagnosticRunner runner = new DiagnosticRunner(diagnostic);;
if(runner.getContainerResult().getState().equals(ResultState.FAILED)) {
	System.out.println("This application needs Java 1.3 or higher to run");
The JDiagnose web and library projects provide support for interacting with diagnostics at a higher level.

Writing a Diagnostic

The simplest way to write a diagnostic is by subclassing org.jdiagnose.DiagnosticUnit. This creates a diagnostic that will run all void methods that start with "diagnose" e.g.:

public class MyFirstDiagnostic {
	public void diagnoseOddMillisSince1970() throws DiagnosticException {
		if(System.currentTimeMillis() % 2 == 0) {
			throw new DiagnosticException("Panic! It seems that there have been an even number of milliseconds "
			 + "since January the 1st 1970");

Diagnostics should be written so that they're easy to set up from vanilla Java or with an IoC container (using setter based dependency injection currently). So, if you need any configuration or external objects set into your diagnostic, just create appropriate setter methods.