7

This project is using Ant as its build system. Can I debug the project when I run it via Ant?

calvin
  • 870
  • 1
  • 13
  • 22

3 Answers3

6

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.

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.

Community
  • 1
  • 1
peter.petrov
  • 38,363
  • 16
  • 94
  • 159
  • 1
    Oh 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
2

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).

Gayan Weerakutti
  • 11,904
  • 2
  • 71
  • 68
1

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.

Community
  • 1
  • 1
Vadzim
  • 24,954
  • 11
  • 143
  • 151