Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 732
Chris Steinbach Avatar asked Oct 18 '22 02:10

Chris Steinbach


2 Answers

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.

like image 132
Santosh Avatar answered Oct 20 '22 22:10

Santosh


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

like image 25
Gaskoin Avatar answered Oct 21 '22 00:10

Gaskoin