Search code examples
javaeclipseremote-debugging

Debugging Remote Java Application -


I am trying to debug java application. I followed this steps

Error:

   Failed to connect to remote VM. Connection refused.
   Connection refused: connect

Program:

   package test;

   public class test {

   public static void main(String[] args) {
    // TODO Auto-generated method stub
    System.out.println("Got");
   }
  }

Steps:

 Eclipse --> Run --> Debug Conf --> connect tab  --> test is project name 
 --> host is localhost --> port is 8000 --> Socket Attach --> Apply --> 
 Debug under common tab --> apply

It shows me that error. Then i checked for the following

ping localhost - Works
telnet localhost 8000 - connection refused
netstat -tna | grep 8000 - no process is listening

How do i achieve this? What else should i modify? Or is there anyother way to achieve this?

Host: localhost windows


Solution

  • If you want to connect to a remote application, the application has to be started in "debug" mode. Otherwise you won't be able to connect.

    You have to set the -xdebug options for this and make sure, you're application is in some way available while you're connecting to it.

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

    Then you are able to connect.

    If you can start your program from within eclipse, it's much easier. Just use

    • Right click on the class you want to start (your main class)
    • Debug As --> java application