ant debugging in eclipse

2019-01-17 11:15发布

I would like to know about 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.

标签: java eclipse ant
6条回答
放荡不羁爱自由
2楼-- · 2019-01-17 11:29

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.

查看更多
Deceive 欺骗
3楼-- · 2019-01-17 11:34

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.

查看更多
唯我独甜
4楼-- · 2019-01-17 11:35

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
查看更多
霸刀☆藐视天下
5楼-- · 2019-01-17 11:42

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.

查看更多
Bombasti
6楼-- · 2019-01-17 11:45

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.

查看更多
劳资没心,怎么记你
7楼-- · 2019-01-17 11:45

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.

查看更多
登录 后发表回答