This project is using Ant as its build system. Can I debug the project when I run it via Ant?
-
3Ant has nothing to do with it. Ant is a build tool. Debugging is at run time. – Boris the Spider Nov 28 '14 at 23:13
-
@BoristheSpider if you are working with a complex buildfile, debugging it step by step could help you to understand how is it actually building your project. – Jaime Hablutzel Aug 16 '16 at 07:54
-
I'm a big fan of IntelliJ IDEA but specifically for this task Eclipse does a great job – Jaime Hablutzel Aug 16 '16 at 07:56
3 Answers
Ant is mainly used for building, not for running Java apps.
But OK, I assume you're running your app using the ant Java task.
If so, yes, you can do that by using remote debugging.
Remote debugging a Java application
In fact you can debug any Java app like that.
Apps started through ant are still Java apps.

- 1
- 1

- 38,363
- 16
- 94
- 159
-
1Oh of course! I shouldn't be running my app through ant, just building the app. This is exactly what the knowledge I needed. Thank you. – calvin Nov 28 '14 at 23:21
-
And how do you add the agentlib when running an ant task? I can't see a place to specify JVM arguments. Edit: Ah I see, right click the Ant task in the "Ant Build" panel, `Properties`, `Execution`, `Ant command line` – Michel Jung Jun 06 '17 at 12:12
Include this line in your java runtime task, in your build.xml:
<jvmarg value="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005"/>
So for instance if it's ant junit task, it will be like:
<target name="test" depends="test-compile">
<junit showoutput="yes" fork="true">
<jvmarg value="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005"/>
</junit>
</target>
Then run your target
ant clean test
Ant test will wait until we connect a debugger. It will show the output:
test:
[junit] Listening for transport dt_socket at address: 5005
Then simply create, run a remote run/debug configuration in Intellij (or in your preferred IDE).

- 11,904
- 2
- 71
- 68
There is a specialized IDEA plugin for debugging ant scripts sources with breakpoints:
https://plugins.jetbrains.com/plugin/7195?pr=idea
https://github.com/opticyclic/antdebugger/
Or the same approach can be used as for ant debugging in eclipse.
-
-
@reversiblean, yes, this answer is about debugging ant scripts in build.xml, not the project that is built with them. It appears, I was tricked by vague wording of the question. – Vadzim May 02 '18 at 07:12