Chris Steinbach
Chris Steinbach

Reputation: 118

Java remote debugging - how can I keep debugger listening?

I'm using IntelliJ IDEA to remote debug a Java CLI program with the debugger listening for connections.

This works fine for the first invocation, but the debugger stops listening after the CLI program disconnects. I want the debugger to keep listening since multiple CLI invocations will be made (in sequence, not in parallel) and only one of these will trigger the breakpoint I've set.

Here's my client debug config:

-agentlib:jdwp=transport=dt_socket,server=n,address=5005,suspend=y

Is it possible to keep the debugger listening?

Upvotes: 5

Views: 3229

Answers (5)

Pierre
Pierre

Reputation: 2912

Try with suspend=n:

-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005

On my local app (tomcat web app), even though I run on JDK8, I still use the older way of doing it and it works fine (another thing you could try):

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

Upvotes: 0

Gaskoin
Gaskoin

Reputation: 2485

It depends also what you are trying to achieve. If you want to check what parameters are passed to your CLI you can just log them to the file or save any information that you need in DB (or file as well).

Upvotes: 1

DavidW
DavidW

Reputation: 1421

When setting up your run configuration, did you select the "Listen" Debugger mode? The command line arguments you show look like the normal "Attach" settings, whereas the arguments for "Listen" look like this: -agentlib:jdwp=transport=dt_socket,server=n,address=yourhost.yourdomain:5005, suspend=y,onthrow=<FQ exception class name>,onuncaught=<y/n> (Specifically, your arguments are missing the address for the application - your CLI program - to connect to IDEA at on start-up.)

I read a post that suggests the "onthrow" argument may not be necessary for general debugging, but I haven't tried it myself.

Upvotes: 0

Santosh
Santosh

Reputation: 886

Well since your CLI program terminates, debugger also stops. If you still want to continue debugger session for multiple runs of CLI program, then you can try as below,

Write a wrapper program from which you invoke your CLI program multiple times and debug the wrapper program instead of your CLI program.

Something like this,

public class Wrapper {
    public static void main(String[] args) {
        YourCLIProgram yp = new YourCLIProgram();
        // First Invocation
        String[] arg1 = { }; // Arguments required for your CLI program
        yp.main(arg1);
        // Second Invocation
        String[] arg2 = { }; // Arguments required for your CLI program
        yp.main(arg2);
        // Third Invocation
        String[] arg3 = { }; // Arguments required for your CLI program
        yp.main(arg3);
        // Fourth Invocation
        String[] arg4 = { }; // Arguments required for your CLI program
        yp.main(arg4);

    }
}

I hope it works.

Upvotes: 2

egorlitvinenko
egorlitvinenko

Reputation: 2776

In JPDA by specification transport service could support or not multiple connections. For example, in Eclipse it doesn't. I suppose the same for IDEA.

Upvotes: 0

Related Questions