debug custom ant-task with eclipse

Imagine, one of your colleagues wrote an ant-task and you have to modify it, but you have no idea how it works.

The counter-task is just an example which is provided with 2 arguments (start and end) and counts the interval line by line, so nothing serious 😉


first, the task:

package org.jtaddeus.example;


public class AntCounterTask extends Task {  
	private int start;
	private int end;
	public void setStart(int start) {
        this.start = start;
	public void setEnd(int end) {
        this.end = end;
    public void execute() {
		for (int i=this.start; i<this.end; i++)

and the pom for the task:

<?xml version="1.0" encoding="UTF-8"?>


second, the debugging-example:

<project name="debug-example" default="default" basedir=".">

	<property name="lib.dir" location="${basedir}/libs"/>
	<taskdef name="counterTask" classname="org.jtaddeus.example.AntCounterTask">
			<pathelement location="${lib.dir}/ant-counter-task-1.0-SNAPSHOT.jar"/>

	<target name="default">
		<counterTask start="5" end="15"/>


and the output:

Buildfile: D:\Dropbox\Christoph\devapps\eclipse-workspace2\debug-example\build.xml
[counterTask] 5
[counterTask] 6
[counterTask] 7
[counterTask] 8
[counterTask] 9
[counterTask] 10
[counterTask] 11
[counterTask] 12
[counterTask] 13
[counterTask] 14
Total time: 13 seconds

Now you have to start the ant-task with some special params. You can do this via shell-call by setting ANT_OPTS :

set ANT_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9999

or, if you like to stay in your eclipse-ide, you can pass them via run-config:


After starting the ant-build with this configuration, you will see nothing, because the jvm will wait vor a remote-debugger that will connect to localhost:9999

You create a remote-debugger in this way:




Now if the ant-build is still running and you start the remote-debugging AND (!) you’ve set several breakpoints in your custom task, the debugging-perspective will open up and let you easily debug your task.