Debug a Junit Ant Task from Eclipse

Sometimes you run into a test that works when run from within Eclipse but not from the command line. To debug the failing test from Eclipse, you can configure the Junit ant task to accept remote debugging sessions.

This can be done by adding the following lines to the junit task:

<junit fork="true">
		
		<!-- For remote debugging from Eclipse -->
		<jvmarg value="-Xdebug" />
		<jvmarg value="-Xnoagent" />
		<jvmarg value="-Djava.compiler=NONE" />
		<jvmarg 
value="-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y" />

This will make the task wait for an incoming debug connection on port 8787. It is necessary to have the fork attribute on the junit task set to true, because the jvmarg values can only be given to a starting Java virtual machine.

Non-ASCII chars in Java

If you are having problems with non-ASCII characters (for example the Danish æ, ø and å) not showing up correctly in your Java application, try giving the Java VM the following argument:

-Dfile.encoding=UTF-8

You can verify that the charset has been set with this statement:

Charset.defaultCharset();