开发者

ant debugging in eclipse

I would like to know abou开发者_StackOverflow社区t the debugging capabilities of ANT using eclipse. Basically I have an ANT build script written by a colleague and I wanted to step through each target to see what are the various tasks that are beings called.


You can do this in Eclipse with these steps:

  1. Be sure to open your build file in the ANT editor (right click on build file -> Open with -> Ant editor).
  2. Double click in the left margin of your build file where you want breakpoint.
  3. Open the Ant view (Window -> Show view -> Ant).
  4. If the build file isn't in the view then you can simply add it.
  5. Once added right click on the ant target you want to run and select Debug as -> Ant build
  6. The Debug perspective should open up and the process should stop at your breakpoint where you can step through it
  7. Sometimes it is required to set the arguments at the time of debugging. It can be set by selecting: Debug as -> Ant build. And then need to select Arguments. And then values can be entered as: -Dprop.name=property value


Create a script antdebug.sh which sets the environment variable ANT_OPTSbefore starting ant

#!/bin/bash
set -e
export ANT_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=2607"
# now execute ant
exec ant "$@"

Afterwards you can remote attach to it using your IDE. Please note the suspend=y, it will suspend the execution until you are attached.


Since ant is just a Java application, you can just add a debug configuration (type Java Application) to eclipse. See Running Ant via Java for how to invoke Ant as if it were a Java application. I'll assume you know how to debug a Java app in Eclipse, so that should get you the rest of the way. If not, ask and I'll expand on this.


With large ant files, or large java projects, when we may have multiple ant files calling each other, I've found that a dependency graph is very useful. I've used Grand to this purpose.

Of course, this will not help much if you want to debug the sequence of instructions inside a particular target.


Before you dive deep into Ant internals, it may be worth trying to run the script with -d (debug) flag and observe the output. Assuming that you are interested in understand how the particular Ant script is working (or not working) and not Ant itself.

If Ant is your area of interest, the answers above are the direction to follow.


add below xml tag to ant build.xml after target init

<javac srcdir="${src.java.dir}" destdir="${target.build.dir}" includeantruntime="true" source="${source}" target="${target}" debug="true" debuglevel="lines,vars,source" classpathref="main.classpath" fork="true" memoryinitialsize="512m" memorymaximumsize="512m" />

if the javac is already there make sure to add debug="true" debuglevel="lines,vars,source" to have a interactive debug session.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜