Ant – How Do I Remote Debug Java Code in Ant and Eclipse

If we execute the Junit test cases in Ant (most of the time we do) and some cases fail, we may expect to debug Java code in Ant to analyze the failures. This tutorial will demonstrate how to remote debug Java code in ant and Eclipse.

1. Open the ant build.xml, find the Java execution task java, add the following nested elements jvmarg to specify arguments for the forked VM, it will launch the java program in ant with debugging turned on mode, and the remote debugger port will be ready on port 5555 to listen collections.

<jvmarg value="-Xdebug"/>
<jvmarg value="-Xnoagent"/>
<jvmarg value="-Xrunjdwp:transport=dt_socket,address=5555,server=y,suspend=y"/>
If the value is y, the target application listens for a debugger application to attach. Otherwise, it attaches to a debugger application at the specified address.
This is the transport address for the connection. If the server is n, attempt to attach to a debugger application at this address. Otherwise, listen for a connection at this port.
If the value is y, the target VM will be suspended until the debugger application connects.

Here goes a whole examples:

<java classname="${}" fork="yes" failonerror="false" maxmemory="512m">
  <jvmarg value="-Xdebug"/>
  <jvmarg value="-Xnoagent"/>
  <jvmarg value="-Xrunjdwp:transport=dt_socket,address=5556,server=y,suspend=y"/>
  <arg value="${src.dir}"/>
  <classpath refid="app.classpath"/>
    <pathelement path="${java.dir}/lib/tools.jar"/>
    <pathelement path="${oc4j.dir}/j2ee/home/oc4j.jar"/>
    <pathelement path="${oc4j.dir}/j2ee/home/jazncore.jar"/>
    <pathelement path="${oc4j.dir}/j2ee/home/jazn.jar"/>
    <fileset dir="${oc4j.dir}/j2ee/home/lib/"/>

2. Open eclipse, set the break point in your code, then navigate:

Run->Debug Configuration->Add a new Remote Java application

From the newly created launch configuration, specify the project, host and port for target application, click ‘apply’ and then click ‘debug’ to start debug in Ant.

Оцените статью
Добавить комментарий

Your email address will not be published. Required fields are marked *



  1. A B

    I was wondering, if you know of a way to debug and ANT script in Eclipse that is invoked from a python script ( also in Eclipse ) using os.system in python.

    My script runs this way, but I can’t debug the ANT script when invoked this way

    Thank you