Thursday, July 15, 2010

Debugging throug Ant

To add debug options to java 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>

<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.

No comments:

Post a Comment