Java debug options in ant build.xml

To add debug options to java (Sun's JDK) command line:
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9009
If the java process runs and terminates itself, change suspend=y, so you can have a chance to attach the remote debugger.

To add the same debug options to ant build.xml java task:
<target name="run">
<java fork="on"
failonerror="true"
classpath="xxx"
classname="xxx">
<jvmarg line="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9009" />
<arg line="--arg1 arg2 --arg3 arg4"/>
</java>
</target>
Or, with the newer -agentlib option:
<target name="test" depends="compile">
<junit printsummary="yes" haltonerror="no" haltonfailure="no" fork="true">
<formatter type="plain" usefile="false"/>
<formatter type="xml"/>
<test name="FooBeanTest"
todir="xxx"/>
<jvmarg line="-agentlib:jdwp=transport=dt_socket,address=localhost:9009,server=y,suspend=y" />
<classpath>
<path refid="test.compile.classpath"/>
<path refid="javaee.classpath"/>
<pathelement path="${build.dir}"/>
<pathelement path="${junit.jar}"/>
</classpath>
</junit>
</target>
Note: <arg> and <jvmarg> take either line or value attribute, but value attributes are treated as one single argument that may contain spaces. So in our case line attribute is used to specify multiple arguments separated by spaces. If value attribute was used instead of line attribute, the debug options will not take effect.

Followers

Pageviews Last 7 Days