从 Eclipse 调试 Ant 任务

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15380429/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 20:10:25  来源:igfitidea点击:

Debug Ant task from eclipse

javaeclipseant

提问by clamp

I am developing a custom ant task with java in the eclipse ide.

我正在 eclipse ide 中使用 java 开发自定义 ant 任务。

is it somehow possible to debug it? that is put a breakpoint on the java line and when ant is executed, it stops there and i can step through the code?

是否有可能调试它?那是在 java 行上放置一个断点,当执行 ant 时,它会停在那里,我可以单步执行代码吗?

edit: since this question has been closed as duplicate, i want to elaborate why it is quite different.

编辑:由于这个问题已被重复关闭,我想详细说明为什么它完全不同。

i am looking to debug the java code that makes up an ant task and not the just the steps of an ant build. the answers already helped me partially, but i still need to figure out why my eclipse doesnt have Debug Remote Java Application.

我希望调试构成 ant 任务的 java 代码,而不仅仅是 ant 构建的步骤。答案已经部分帮助了我,但我仍然需要弄清楚为什么我的 Eclipse 没有调试远程 Java 应用程序。

回答by Nick Holt

You need to start ANT with the remote debug enabled by entering the following before you run ANT.

在运行 ANT 之前,您需要通过输入以下内容来在启用远程调试的情况下启动 ANT。

set ANT_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005

This will cause the JVM running ANT to pause until you attach your debugger.

这将导致运行 ANT 的 JVM 暂停,直到您附加调试器。

Next you'll need to modify the classpath ANT is using in order to pickup the classes that form the custom task you're writing. I don't think there's a way to do this easily with environment vars, so the quickest thing is to just edit the ant.batfile.

接下来,您需要修改 ANT 正在使用的类路径,以便选取构成您正在编写的自定义任务的类。我不认为有一种方法可以使用环境变量轻松完成此操作,因此最快的方法就是编辑ant.bat文件。

Now when your custom task is run, it will stop at any breakpoints in your IDE.

现在,当您的自定义任务运行时,它将在 IDE 中的任何断点处停止。