[java] Eclipse Error: "Failed to connect to remote VM"

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?

This question is related to java eclipse

The answer is


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%

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'


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


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"

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.


Uninstall and install again ADT android plugin.


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

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)

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.


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!!!!

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%

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


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


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.


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.

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.


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

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.


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.


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 "$@" 

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

service jboss-portal restart

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.")


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


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


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>