Java remote debugging - how can I track debugger listening?

I am using IntelliJ IDEA to remotely debug a Java CLI program with a debugger that listens for connections.

This is great for the first call, but the debugger stops listening after you turn off the CLI program. I want the debugger to continue listening, as several CLI requests will be created (sequentially, not parallel), and only one of them will trigger the breakpoint that I set.

Here is my client debug configuration:

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

Is it possible to listen to the debugger?

+5
source share
5 answers

Well, since your CLI program terminates, the debugger also stops. If you still want to continue the debugger session for several starts of the CLI program, you can try, as shown below,

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

Something like that,

 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 this works.

+2
source

It also depends on what you are trying to achieve. If you want to check which parameters are passed to your CLI, you can simply register them in a file or save any information that you need in the database (or the file as well).

+1
source

In the JPDA , a transport service may or may not support multiple connections. For example, in Eclipse it is not . I believe the same for IDEA.

0
source

When configuring the launch configuration, did you select the "Listen" mode of the debugger? The command line arguments that you show look like the usual โ€œAttachโ€ settings, while 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> (In particular, in your arguments there is no application address - your CLI program - to connect to IDEA at startup.)

I read a post saying that the โ€œonthrowโ€ argument might not be needed for general debugging, but I have not tried it myself.

0
source

Try with suspend = n:

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

In my local application (tomcat web application), even though I am running JDK8, I still use the older way to do this and it works fine (another thing you could try):

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

Source: https://habr.com/ru/post/1273718/


All Articles