35

When ever i tried to launch my eclipse debug(for server side code) i'm getting the following error Failed to connect to remote VM. Connection refused.

What's the problem may be? I already tried with most of the solutions out in the web but none of that solved my issue. Could any one can assist me to fix this? Advance thanks..

suat
  • 4,239
  • 3
  • 28
  • 51
Miko
  • 2,615
  • 9
  • 33
  • 58
  • You should add the command line you are using for starting the server VM - especially the debug parameters. Also details about the used OS on client and server side would be nice. – Robert Mar 08 '12 at 16:06
  • Are you actually connecting to a remote server? If so, there might be firewall issues, etc. If you're running server code on your own machine then i'm clueless. I agree w/ @Robert, more info would be useful. – JHollanti Mar 08 '12 at 16:12

8 Answers8

41

when you have Failed to connect to remote VM Connection refused error, restart your eclipse

Gurwinder Singh
  • 38,557
  • 6
  • 51
  • 76
Subbiah Sudhan
  • 445
  • 1
  • 6
  • 10
40

Which server are you using?

Like already said:

  1. In your debug configuration you'll have to define the right port of your server (GF:9009 / Tomcat:8000)
  2. You'll have to set the JVM property of the server to debug

For Glassfish:

    Log in to admin-console > Configurations > server-config > JVM-Settings > check DEBUG checkbox > restart server

For Tomcat:

create file debug.bat/.sh (depending on your OS) in %TOMCAT_HOME%/bin directory and write

    set JPDA_ADDRESS=8000
    set JPDA_TRANSPORT=dt_socket
    catalina.bat jpda start

in it.

After you've created this file start server by executing debug.bat/.sh.

Now you should be able to debug remotely in Eclipse after you set the necessary properties in your debug configuration.

Hope this helped! Have Fun!

EDIT

If you're running tomcat in a Win environment as a service you don't have a catalina.bat file in the bin-directory of your tomcat installation.
To set your server into debug-mode please try the following:

  1. Run the Configuration option in Windows Menu or run %catalina_home%/bin/tomcat6w.exe
  2. In Java tab, add this line to Java:

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

SimonSez
  • 7,399
  • 1
  • 30
  • 35
  • Thanks for your input!! In my jboss bat file two places i have the server jpda address but i was changed in a place only.. Your point make to concentrate once again.. It's solved!! – Miko Mar 09 '12 at 11:29
  • I have created the debug.bat file in the bin folder of Tomcat7 and added set JPDA_ADDRESS=8000 set JPDA_TRANSPORT=dt_socket catalina.bat jpda start How to start the server by executing debug.bat? When I double click on it, it automatically closes immediately. – Gopakumar N G May 23 '13 at 11:58
  • @GopakumarNG Thats right *your* shell should automatically close after it finished but it should open a new one showing the tomcat service. Please make sure that there aren't any typos in your *debug.bat* especially in the **catalina.bat jpda start** part. – SimonSez May 23 '13 at 12:28
  • @SimonSez There are no typos in the debug.bat file. But there is no catalina.bat file in Tomcat's bin directory, I am using apache-tomcat-7.0.40. Does it will cause any problem? – Gopakumar N G May 23 '13 at 12:36
  • @GopakumarNG not AFAIK. I've just tested it myself with the latest tomcat distro for win x64 and got no problems. Maybe you should just try to reinstall the whole server or try to extract the *catalina.bat* out of the *tomcat.zip* to your bin directory. Just FYI: in your *debug.bat* you reference this *catalina.bat* so it's an essential file you'll definitely need. Your server shouldn't start at all, not even in normal mode! Cheers – SimonSez May 23 '13 at 12:54
  • @SimonSez I have downloaded the zip file and copied catalina.bat to bin directory. Now the debug.bat just opens on clicking and shows "bad version number" and automatically closes again. – Gopakumar N G May 23 '13 at 13:05
  • @GopakumarNG Sorry but I've never got this error, so I'm no help. I can just guess: Do you have a new Java **SDK** version (min. vers. 6)? Take a look at [this](http://stackoverflow.com/questions/4072260/how-to-change-java-version-used-by-tomcat) where someone is facing a similiar problem. Also I've edited my post to give you another hint. Cheers. – SimonSez May 23 '13 at 13:19
  • @SimonSez I am using jdk7. Anyway thanks for the replies. – Gopakumar N G May 23 '13 at 13:26
  • @SimonSez I am using CentOS and want to run tomcat 8.0.12 in debug mode. When I run debug.sh file, I got error "debug.sh: line 3: catalina.bat: command not found". I can see that catalina.bat is present there. Just saying should I replace 3rd line with "catalina.bat jpda start" as I am running centOS? – Saad Qureshi Nov 18 '15 at 11:52
  • 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. – Puneet Lamba Apr 18 '20 at 15:40
6

Sometimes the port which you are trying to access, gets occupied and won't be released. Try some tools to find whether the port is in use or not. I also faced the same issue. I tried giving different port numbers but unfortunately it didn't work. I tried restarting the system (not the application server), and it worked :)

sunil
  • 61
  • 1
  • 1
4

I faced the same issue. But i resolved it by changing my port numbers to different one.

Raman Sahasi
  • 30,180
  • 9
  • 58
  • 71
Ravi Krishna P
  • 139
  • 1
  • 8
3
  • The port number in the Eclipse configuration and the port number of your application might not be the same.
  • You might not have been started your application with the right parameters.

    Those are the simple problems when I have faced "Connection refused" error.

suat
  • 4,239
  • 3
  • 28
  • 51
1

As suat said, most of the time the connection refused is due to the fact that the port you set up is in use or there is a difference between the port number in your remote application debugging configuration in Eclipse and the port number used in the address attribute in

-Xrunjdwp:transport=dt_socket,address=1044,server=y,suspend=n.

Check those things. Thanks!

xlecoustillier
  • 16,183
  • 14
  • 60
  • 85
1

If you need to debug an application working on Tomcat, make sure that your Tomcat-folder/bin/startup.bat (if using windows) contains the following lines:

set JPDA_TRANSPORT="dt_socket"
set JPDA_ADDRESS=8000

call "%EXECUTABLE%" jpda start %CMD_LINE_ARGS%
Abdelhameed Mahmoud
  • 2,118
  • 2
  • 22
  • 17
0

I ran into this problem debugging play framework version 2.x, turned out the server hadn't been started even though the play debug run command was issued. After a first request to the webserver which caused the play framework to really start the application at port 9000, I was able to connect properly to the debug port 9999 from eclipse.

[info] play - Application started (Dev)

The text above was shown in the console when the message above appeared, indicating why eclipse couldn't connect before first http request.

Andreas
  • 545
  • 1
  • 4
  • 16