Failed to connect to remote VM. Connection refused. while tring to debug jar

18,661

Solution 1

Did you remember to enable debugging on the JVM you are trying to connect to? This is done through JAVA_OPTS when you run the remote JVM.

For example, to add debugging to tomcat, you would add these JAVA_OPTS when launching the java process:

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

Solution 2

Make sure you're adding the debug flags BEFORE the reference to your Java program, otherwise they will be passed to the program itself rather than to Java.

Also, Eclipse can be weird sometimes and it doesn't automatically switch to the "Debug" perspective when you run the "Debug Configuration". After a successful debug session has been established, if you run it again thinking that it didn't run and/or silently failed, then you get the error message: "Failed to connect to remote VM. Connection refused." So, always switch to the "Debug" perspective to see what's going on.

Share:
18,661
shraddha
Author by

shraddha

Updated on June 04, 2022

Comments

  • shraddha
    shraddha almost 2 years

    I am trying to debug the jar file with Remote JAVA Application debug. I am getting 'Failed to connect to remote VM. Connection refused.' error following is stack trace..

    java.net.ConnectException: Connection refused: connect at java.net.DualStackPlainSocketImpl.connect0(Native Method) at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:69) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391) at java.net.Socket.connect(Socket.java:579) at java.net.Socket.connect(Socket.java:528) at java.net.Socket.(Socket.java:425) at java.net.Socket.(Socket.java:208) at org.eclipse.jdi.internal.connect.SocketTransportService$2.run(SocketTransportService.java:136) at java.lang.Thread.run(Thread.java:722)

  • shraddha
    shraddha almost 12 years
    Yes I am using following command java -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=555‌​00 -jar myjar.jar Also I'm using same port number in eclipse debug configuration and in command
  • shraddha
    shraddha almost 12 years
    It was able to find the bug,the host IP in debug configuration was different in my case it should be of my local machine...
  • mKay
    mKay about 3 years
    Thank you, the switch to debug view did the trick. This is so dumb! Such issues are the reason I detest eclipse.