Search code examples
javadebuggingintellij-ideajarremote-debugging

Unable to open debugger port through IntelliJ


I've got a server running on DigitalOcean and a JAR file that I want to debug. I first start the JAR on the remote server using

java -jar Server.jar -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005

but on the console I see no output like "listening on port 5005...".

When I press debug in IntelliJ it says

unable to open debugger port (198.xxx.xxx.xx:5005): java.net.ConnectException "Connection refused"

This is my IntelliJ configuration:
enter image description here

I also tried using -Xdebug but it still didn't work.

If I set suspend=y it should wait until a debugger is connected, but instead, it starts without problems.


Solution

  • The command to start the remote Java process in debug mode looks correct. If you don't see "Listening to Port blah" when you start the server JAR, then it might mean that the debug args are not being picked up. Another way to quickly check this would be to test with a telnet localhost 5005 on the machine where the server JAR is being executed. The telnet will fail if that port is not being used.

    I suggest that you try the following, since the order of the parameters might be significant (I'll add some official evidence for this later):

    java "agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005" -jar Server.jar