46

I’m getting the following error when I start Debug from the Eclipse IDE.

Message: “Failed to connect to remote VM. Connection Refused”

What could be the reason?

Lii
  • 11,553
  • 8
  • 64
  • 88
softwarematter
  • 28,015
  • 64
  • 169
  • 263
  • Are you trying to debug a local application or a remote one? – Rob H Jun 10 '09 at 13:47
  • 4
    Note that if you're trying to debug a local application and you're getting this error, it could be because your /etc/hosts (or C:\WINDOWS\system32\drivers\etc\hosts) file has a bogus mapping for "localhost". I've seen that before. – David Citron Jun 10 '09 at 17:35
  • 1
    If you're debugging a remote java application, open the debug perspective, check whether there is any vm already attached. Eclipse could not show the debug perspective util it encouter a breakpoint. – Jichao Mar 08 '15 at 09:37
  • make sure your application server is up and listening to the correct port. – Katta Nagarjuna Jul 03 '17 at 19:56
  • I right-clicked the Debug perspective button and selected reset. It worked accordingly. – Bernard Apr 23 '15 at 07:53
  • Note, the port can only accept **one** connection and any subsequent connections will be rejected. – IliasT Sep 06 '17 at 01:56
  • Check if you wrongly specified Port 8080 instead of 8000. It was happened with me. – Shriprasad Jul 09 '12 at 10:01

26 Answers26

38

Use 0.0.0.0 for addresses to be able to connect form any remote machine i.e.:

-Xdebug -Xrunjdwp:transport=dt_socket,address=0.0.0.0:8000,server=y,suspend=y
Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
junaid
  • 21
  • 2
  • 2
  • 6
    This appears to be a recent change (JDK 9+)...if you only specified the port, it would accept connections from any IP to that port. Now, you need to manually specify the IP or use 0.0.0.0 if you want anything to connect. – Steven Feb 19 '20 at 18:48
  • fix it for me under: openjdk version "1.8.0_232" OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_232-b09) OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.232-b09, mixed mode) – Xanlantos Mar 18 '20 at 09:31
  • I wish this answer had been easier to find...I almost gave up trying to configure remote debug with Maven on a Raspberry Pi. – jawsware Sep 26 '20 at 01:10
  • 1
    Or use * instead of 0.0.0.0 – Suma Oct 13 '21 at 12:35
34

Have you setup the remote VM to accept connections?

java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=10000,suspend=n yourServer

Is there a firewall in the way?

Are you specifying the correct host / port?

Are you connected to a VPN?

Community
  • 1
  • 1
Glen
  • 21,816
  • 3
  • 61
  • 76
  • 6
    The gotcha for me was accidentally adding the debug flags to the end of the command line, so they were just passed to the program itself. – Sam Brightman Sep 14 '11 at 06:33
  • 4
    What is the param "yourServer" match with ? It seems to be a java class ... How to setup it correctly ? – nonozor Nov 16 '12 at 09:59
  • my Debug Configurations in eclipse had changed my port number. :( – user2847749 May 19 '15 at 18:09
  • I had reinstalled (via RPM) and forgotten to modify my /etc/init.d script to include the jpda flag – InfernalRapture Jul 10 '15 at 20:13
  • Closing the VPN connection helped me :) – gbgnv Oct 15 '16 at 22:10
  • are you running this command in remote machine or in your machine where eclipse is present? – Madhusudan May 22 '17 at 09:05
  • For me, it was a port issue as suggested in the second question, I had to switch to port 5005 (default) – ShacharSh Nov 16 '17 at 14:23
  • If the port number and hostname(mine's localhost), what else could be the issue? – committedandroider Oct 11 '19 at 21:22
  • 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:43
33

Remove your proxy from eclipse!

Go to network Connections within General Preferences ( Windows -> Preferences ) and set "Active Provider" to "Direct"

remove proxy

Reboot your Eclipse after that

A. Ocannaille
  • 306
  • 4
  • 14
Natan Lotério
  • 689
  • 1
  • 10
  • 20
4

David Citron is right -- if localhost is not resolving properly, it can cause this problem. Here's how to test:

If it works when your PC is not connected to the net (no WiFi, no network cables). If it does work under those conditions, then it may be that you need to make sure that addresses are resolving to localhost properly. The messages that DDMS and adb.exe use for debugging and communicating to the VM must properly resolve to localhost on your PC. (Yes, it's odd that other commands using DDMS & adb work just fine but debugging doesn't. Seems that something in DDMS or adb needs to be standardized so they all work under the same conditions.)

If you need to make sure that things are resolving to localhost properly:

1) Make sure that this line is in your /Windows/System32/drivers/etc/hosts file:

127.0.0.1  localhost

(you can have any amount of whitespace between "127.0.0.1" and "localhost")

And -- as David Citron suggested -- make sure that the hosts file is valid and doesn't have cruft or errors in it.

2) If that doesn't work, then you may need to also add your PC's IPv4 address to the hosts file, and resolve it to localhost. (You can find out the IPv4 address for your machine with the ipconfig command.) If, for example, your machine's IPv4 address is 192.168.1.100 then you'd add the line

192.168.1.100  localhost

to your hosts file. (You can add it below the "127.0.0.1 localhost" line in the file.)

You can verify that adb (and your emulator if you're running one) is listening on ports by using the netstat -b command. (Note that you need admin privileges for the -b option. I open a command window using "Run as Administrator.")

aenw
  • 841
  • 9
  • 18
3

Possible Cause for this error:

  1. Your Remote Java Application is not running.
  2. Check your Host and Port, many times these entries are not correct.
  3. Firewall not allowing access to your remote port.

You can also check this how to guide on eclipse remote debugging for more details.

Kevin Panko
  • 8,356
  • 19
  • 50
  • 61
2

add to your run script:

export JPDA_ADDRESS=8787
export JPDA_TRANSPORT=dt_socket
export JPDA_HOST=localhost

JAVA_OPTS=$JAVA_OPTS -Xms128m -Xmx512m -Dsun.rmi.dgc.client.gcInterval=3600000
JAVA_OPTS=$JAVA_OPTS -Dsun.rmi.dgc.server.gcInterval=3600000
JAVA_OPTS=-Xdebug -Xnoagent -Xrunjdwp:transport=$JPDA_TRANSPORT,address=$JPDA_ADDRESS,server=y,suspend=n $JAVA_OPTS
Behe
  • 7,572
  • 3
  • 33
  • 46
lctr30
  • 526
  • 1
  • 4
  • 17
  • Where you wants to run these scripts ? Locally or remote VM machine where we're actually trying to connect? – Jeff Cook Jun 21 '18 at 05:43
2

Our development image only has the Tomcat service installation on it, so setting the environment variables, etc., didn't have any effect. If you need to do this through the Tomcat Windows service, there are a few things you'll need to be aware of:

  • David Citron's comment was the last bit that I needed to get my connection working. The hosts file on our machines has localhost commented out (it's supposedly resolved through the DNS, but that doesn't work for the debug connection). I uncommented it and was able to connect.
  • If user access control is turned on, you'll need to use your admin credentials to access the services control panel or the Tomcat monitor app or whatever you're using to toggle the server state. The monitor app (documented here) is probably the best, because you can both edit the server settings for the debug options and start and stop the server.
  • I thought that perhaps you would need to run Eclipse as an administrator to be able to terminate the Tomcat process, but you don't. Once you have that remote attachment, you're able to work with the service up to termination.
Spanky Quigman
  • 870
  • 7
  • 16
2

I solved it setting in Eclipse:

Windows --> Preferences --> Java --> Debug --> Debugger timeout: 10000

Before I had set "Debugger timeout: 3000" and I had problems with timeout.

Cristian
  • 548
  • 6
  • 8
1

The following worked for me: edit the last line of tomcat startup.sh from

exec "$PRGDIR"/"$EXECUTABLE" start "$@"`

to

export JPDA_ADDRESS=8000 export JPDA_TRANSPORT=dt_socket  
exec "$PRGDIR"/"$EXECUTABLE" jpda start "$@" 
Daniel Beck
  • 20,653
  • 5
  • 38
  • 53
dayanand
  • 147
  • 3
  • 5
1

The solution that worked for me is weird

  1. Simply remove the all the break points
  2. Restart tomcat in debug mode (using catalina.sh jpda start)
  3. Now try to connect and it worked!!!!
Pratik Goenka
  • 2,321
  • 1
  • 27
  • 24
  • its worked for me. first need to start the catalina(so only it can connect to the port) then start the debug in eclipse it will connect to the jpda. thanks – VG__ Apr 03 '19 at 05:27
1

Another possibility is that the debug agent is binding to the wrong network interface.

I've just seen this when trying to debug a Windows 10 JVM inside a VirtualBox VM, and I'm trying to connect from Eclipse running on the VirtualBox host. In my case, the agent only bound to the 127.0.0.1 interface.

To fix, you can qualify the address including the IP of the interface you want to bind to. For example:

java -agentlib:jdwp=transport=dt_socket,server=y,address=192.168.0.5:8000,suspend=n <other arguments>
Dan Gravell
  • 7,855
  • 7
  • 41
  • 64
  • 1
    Was about to add same thing Dan. The server I was trying to debug had two NICs, and the jdwp server was binding to the wrong one. By explicitly setting `address=xxx.xxx.xxx.xxx:8000` I was able to connect just fine. – Andrew Wynham Jun 23 '18 at 15:34
0

If you are using windows os then replace line in tomcat configuration Tomcat6\bin\startup.bat.

Replace

call "%EXECUTABLE%" start %CMD_LINE_ARGS%

with

call "%EXECUTABLE%" jpda start %CMD_LINE_ARGS%
Kevin Panko
  • 8,356
  • 19
  • 50
  • 61
Ishwar Pohani
  • 113
  • 1
  • 1
  • 10
0

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 had the problem with Tomcat running on Ubuntu. The issue was selinux was enabled and for some reason it would not let Eclipse connect to the debugging port. Disabling selinux or putting it in permissive mode solved the issue for me.

sce
  • 190
  • 1
  • 12
0

I get this error for Weblogic after i installed Quicktime and removing QTJava.zip from classpath solves the problem.

https://blogs.oracle.com/adfjdev/entry/java_jre7_lib_ext_qtjava

Yusuf Ismail Oktay
  • 875
  • 1
  • 6
  • 6
0

Increase the memory value of the properties

  • MEM_PERM_SIZE_64BIT
  • MEM_MAX_PERM_SIZE_64BIT

in setDomainEnv.cmd file from %weblogic_home%\user_projects\domains\your_domain\bin

Kevin Panko
  • 8,356
  • 19
  • 50
  • 61
Aline
  • 1
0

I'll add one more possible solution, if you're running this on a virtual machine (vmware, etc.) , some other process on the host or other VM could already have the port you're trying to connect with. Either stop that other process or choose another port.

Chris Gerken
  • 16,221
  • 6
  • 44
  • 59
0

Create setenv.bat file in nib folder of Tomcat. Add SET JPDA_ADDRESS = 8787 ; Override the jpda port Open cmd, go to bin folder of Tomcat and Start tomcat using catalina jpda start Set up a debug point on eclipse Next compile your project. Check localhost:8080/ Deploy the war or jar under webapps folder and this must deploy war on Tomcat. Then send the request. the debug point will get hit NOTE : Don't edit catalina.bat file. make changes in setenv.bat file

Deepika Anand
  • 305
  • 3
  • 6
0

If you are using Jboss:

change in the file jboss7.1.1\bin\standalone.conf.bat the line:

rem set "JAVA_OPTS=%JAVA_OPTS% -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"

to:

set "JAVA_OPTS=%JAVA_OPTS% -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"
0

I tried several things mentioned here, but the below method worked for me:

Go to Debug Console of Eclipse, where you will find the name of the process which is already existing there. Right click on that process and select "Terminate and Remove", this will terminate the process. Now try initiating the process again and it will work.

Nishant Kumar
  • 235
  • 2
  • 4
  • 13
0

In my case i turn Windows Firewall off

1- Open Windows Firewall by clicking the Start button Picture of the Start button, and then clicking Control Panel. In the search box, type firewall, and then click Windows Firewall.

2- Click Turn Windows Firewall on or off. Administrator permission required If you're prompted for an administrator password or confirmation, type the password or provide confirmation.

3- Click Turn off Windows Firewall (not recommended) under each network location that you want to stop trying to protect, and then click OK. Was this page helpful?

Some times you need also

  1. To stop all Vpn client services (fortiClient ,vpn Client ...)
  2. To stop Antivirus Firewall ( exemple Kaspersky => Configuration => Anti-Hacker)
Monsif EL AISSOUSSI
  • 2,296
  • 19
  • 17
0

I am using jboss so solution to your problem was restart.

service jboss-portal restart
0

I've encountered like this in Hybris.

  1. Check your port in Resource Monitor > Network. Check if other service is using your port.

1.2 If yes, then you need to change your properties in project.properties

1.3 Change your address, any available address. In my case, I changed from 8000 to 8080. then save.

java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8080,suspend=n yourServer
  1. In your console, rebuild your ant using command 'ant all'

  2. Then debug again, using the command 'hybrisserver.bat debug'

mzzzzzzz
  • 73
  • 4
0

NOTE: For glassfish Server login via admin console -> Configurations -> server-config -> JVM-settings. * Remember to check Enable checkbox for Debug. Now Note the address, this address will be used in port of eclipse Remote Java Application Debug.Check the snap shot in glassfish server here

Rahul
  • 1
  • 1
0

I had and solved this problem by disconnecting from all remote Java applications in the debug window/perspective and restarting Eclipse. I could connect again after doing so.

anon
  • 4,163
  • 3
  • 29
  • 26
0

Uninstall and install again ADT android plugin.

MarcoDuff
  • 306
  • 2
  • 4