ant debugging in eclipse

强颜欢笑 提交于 2019-12-28 12:02:18

问题


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.


回答1:


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



回答2:


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.




回答3:


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.




回答4:


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.




回答5:


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.




回答6:


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.



来源:https://stackoverflow.com/questions/3039933/ant-debugging-in-eclipse

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!