0

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

Gibbs
  • 16,706
  • 11
  • 53
  • 118

1 Answers1

0

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
Ria
  • 1,154
  • 2
  • 10
  • 20
  • Thanks Ria. I want to debug a program which is running in my windows machine from my ubuntu. Before that i haven't any experience of remote debugging. So i write a simple java program which is in my question and i want to debug it from my windows machine[program is also in the same windows - eclipse] as debugging remote application. How to do this instead doing it from eclipse? – Gibbs Mar 22 '15 at 09:51
  • How do you start the program? Is it a jar or do you run it from the command line? – Ria Mar 22 '15 at 09:54
  • 1
    Try running it with additional parameters `java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000 NameOfYourClass`. When the program is started (and has not completed), connect with the remote debugger like you described. – Ria Mar 22 '15 at 10:07
  • ok Ria What does the port 8000 mean? What program will listen there? I dont understand this part. – Gibbs Mar 22 '15 at 10:09
  • this is the port, you'll be able to connect with the debugger. 8000 ist a standard value but you can change it to any unused port you like. – Ria Mar 22 '15 at 10:23
  • Thanks Ria. I am gonna check the following scenario. Windows Machine, program is in Eclipse. Set break points there and start the debugger by the command you provided from the command line. Do i need to set any other properties ? – Gibbs Mar 22 '15 at 10:26
  • Ria Thanks for your time and great help. I got the output but it doesn't wait at my breakpoint. Do i need to do anything with eclipse like property change – Gibbs Mar 22 '15 at 11:14
  • Hm, that should do. Do you run it with the sample code from your post? Maybe it terminates too quickly. You can try to set 'suppend=y' (instead of 'suspend=n'). Then start your program and connect the debugger. It should stop at your breakpoints then. – Ria Mar 22 '15 at 12:46
  • Well, i am asking too much i guess. It waits for something in the cmd. but ctrl doesn't reach my eclipse. – Gibbs Mar 22 '15 at 13:58
  • Can you connect the debugger? After the debugger is conected the program should continue running an stop if it hits a breakpoint. – Ria Mar 22 '15 at 18:28
  • I run the program in debug mode and it's waiting at the port. Is there anything i should do? [followed last answer](http://stackoverflow.com/questions/975271/remote-debugging-a-java-application) – Gibbs Mar 23 '15 at 04:33
  • You should then be able to connect your debugger in eclipse as you described in your post (without any error message). After this your program should continue running and stop at breakpoints you set. – Ria Mar 23 '15 at 17:22