Java eclipse中的ant调试
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3039933/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ant debugging in eclipse
提问by Jony
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.
我想了解使用 Eclipse 的 ANT 调试功能。基本上,我有一个同事编写的 ANT 构建脚本,我想单步执行每个目标以查看正在调用的各种任务是什么。
回答by Mark Peters
Since ant is just a Java application, you can just add a debug configuration (type Java Application) to eclipse. See Running Ant via Javafor 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.
由于 ant 只是一个 Java 应用程序,因此您可以在 eclipse 中添加调试配置(类型 Java 应用程序)。请参阅通过 Java 运行 Ant,了解如何像调用 Java 应用程序一样调用 Ant。我假设您知道如何在 Eclipse 中调试 Java 应用程序,这样您就可以完成剩下的工作。如果没有,请询问,我会对此进行扩展。
回答by Ross
You can do this in Eclipse with these steps:
您可以通过以下步骤在 Eclipse 中执行此操作:
- Be sure to open your build file in the ANT editor (right click on build file -> Open with -> Ant editor).
- Double click in the left margin of your build file where you want breakpoint.
- Open the Ant view (Window -> Show view -> Ant).
- If the build file isn't in the view then you can simply add it.
- Once added right click on the ant target you want to run and select Debug as -> Ant build
- The Debug perspective should open up and the process should stop at your breakpoint where you can step through it
- 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
- 确保在 ANT 编辑器中打开您的构建文件(右键单击构建文件 -> 打开方式 -> Ant 编辑器)。
- 在构建文件的左边距中双击要断点的位置。
- 打开 Ant 视图(窗口 -> 显示视图 -> Ant)。
- 如果构建文件不在视图中,那么您可以简单地添加它。
- 添加后右键单击要运行的 ant 目标并选择 Debug as -> Ant build
- Debug 透视图应该打开,并且该过程应该在您可以单步执行的断点处停止
- 有时需要在调试时设置参数。可以通过选择进行设置:Debug as -> Ant build。然后需要选择 Arguments。然后值可以输入为:-Dprop.name=property value
回答by Miro A.
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.
在深入研究 Ant 内部之前,可能值得尝试使用 -d(调试)标志运行脚本并观察输出。假设您有兴趣了解特定的 Ant 脚本如何工作(或不工作)而不是 Ant 本身。
If Ant is your area of interest, the answers above are the direction to follow.
如果 Ant 是您感兴趣的领域,那么上面的答案就是您要遵循的方向。
回答by rsarro
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 Grandto this purpose.
对于大型 ant 文件,或大型 java 项目,当我们可能有多个 ant 文件相互调用时,我发现依赖关系图非常有用。我已经将Grand用于此目的。
Of course, this will not help much if you want to debug the sequence of instructions inside a particular target.
当然,如果您想调试特定目标内的指令序列,这将无济于事。
回答by reto
Create a script antdebug.sh
which sets the environment variable ANT_OPTS
before starting ant
创建一个脚本antdebug.sh
,ANT_OPTS
在启动 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.
之后,您可以使用 IDE 远程连接到它。请注意suspend=y
,它将暂停执行,直到您被附加。
回答by tk_
add below xml tag to ant build.xml
after target init
build.xml
在目标初始化之后将下面的 xml 标记添加到 ant
<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.
如果 javac 已经存在,请确保添加debug="true" debuglevel="lines,vars,source"
一个交互式调试会话。