Java Eclipse 错误:“无法连接到远程 VM”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/975384/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Eclipse Error: "Failed to connect to remote VM"
提问by devnull
I'm getting the following error when I start Debug from the Eclipse IDE.
当我从 Eclipse IDE 启动调试时出现以下错误。
Message:
“Failed to connect to remote VM. Connection Refused”
信息:
“Failed to connect to remote VM. Connection Refused”
What could be the reason?
可能是什么原因?
采纳答案by Glen
Have you setup the remote VM to accept connections?
您是否已将远程 VM 设置为接受连接?
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?
您是否已连接到 VPN?
回答by lctr30
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
回答by Spanky Quigman
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:
我们的开发镜像上只有Tomcat服务安装,所以设置环境变量等没有任何作用。如果您需要通过 Tomcat Windows 服务执行此操作,则需要注意以下几点:
- 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.
- David Citron 的评论是我需要让我的连接正常工作的最后一点。我们机器上的主机文件将 localhost 注释掉了(据说它是通过 DNS 解析的,但这对调试连接不起作用)。我取消了它的注释并且能够连接。
- 如果用户访问控制已打开,您将需要使用您的管理员凭据来访问服务控制面板或 Tomcat 监视器应用程序或用于切换服务器状态的任何内容。监视器应用程序(此处记录)可能是最好的,因为您既可以编辑调试选项的服务器设置,也可以启动和停止服务器。
- 我认为您可能需要以管理员身份运行 Eclipse 才能终止 Tomcat 进程,但您不需要。拥有该远程附件后,您就可以使用该服务直至终止。
回答by Jeevan Pratap
Possible Cause for this error:
此错误的可能原因:
- Your Remote Java Application is not running.
- Check your Host and Port, many times these entries are not correct.
- Firewall not allowing access to your remote port.
- 您的远程 Java 应用程序没有运行。
- 检查您的主机和端口,很多时候这些条目是不正确的。
- 防火墙不允许访问您的远程端口。
You can also check this how to guide on eclipse remote debuggingfor more details.
您还可以查看如何指导 eclipse 远程调试以获取更多详细信息。
回答by Brian Bowman
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.
我通过在调试窗口/透视图中断开与所有远程 Java 应用程序的连接并重新启动 Eclipse 来解决这个问题。这样做后我可以再次连接。
回答by MarcoDuff
Uninstall and install again ADT android plugin.
卸载并重新安装 ADT android 插件。
回答by aenw
David Citron is right -- if localhost is not resolving properly, it can cause this problem. Here's how to test:
David Citron 是对的——如果 localhost 没有正确解析,就会导致这个问题。以下是测试方法:
If it works when your PC is not connectedto the net (no WiFi, no network cables). If it does workunder those conditions, then it may be that you need to make sure that addresses are resolving to localhostproperly. The messages that DDMS and adb.exe use for debugging and communicating to the VM must properly resolve to localhoston 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.)
如果它在您的 PC未连接到网络(没有 WiFi,没有网线)时工作。如果它确实在这些条件下工作,那么您可能需要确保地址localhost正确解析。DDMS 和 adb.exe 用于调试和与 VM 通信的消息必须localhost在您的 PC 上正确解析。(是的,奇怪的是,使用 DDMS 和 adb 的其他命令工作得很好,但调试却没有。似乎 DDMS 或 adb 中的某些内容需要标准化,以便它们都在相同的条件下工作。)
If you need to make sure that things are resolving to localhostproperly:
如果您需要确保事情localhost正确解决:
1) Make sure that this line is in your /Windows/System32/drivers/etc/hostsfile:
1) 确保此行在您的/Windows/System32/drivers/etc/hosts文件中:
127.0.0.1 localhost
(you can have any amount of whitespace between "127.0.0.1" and "localhost")
(“127.0.0.1”和“localhost”之间可以有任意数量的空格)
And -- as David Citron suggested -- make sure that the hosts file is valid and doesn't have cruft or errors in it.
并且——正如 David Citron 所建议的——确保主机文件是有效的,并且没有多余的内容或错误。
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 ipconfigcommand.) If, for example, your machine's IPv4 address is 192.168.1.100then you'd add the line
2) 如果这不起作用,那么您可能还需要将 PC 的 IPv4 地址添加到主机文件中,并将其解析为localhost. (您可以使用该ipconfig命令找出您的机器的 IPv4 地址。)例如,如果您的机器的 IPv4 地址是,192.168.1.100那么您将添加以下行
192.168.1.100 localhost
to your hosts file. (You can add it below the "127.0.0.1 localhost" line in the file.)
到您的主机文件。(您可以将其添加到文件中的“127.0.0.1 localhost”行下方。)
You can verify that adb (and your emulator if you're running one) is listening on ports by using the netstat -bcommand. (Note that you need admin privileges for the -boption. I open a command window using "Run as Administrator.")
您可以使用该netstat -b命令验证 adb(以及您的模拟器,如果您正在运行)是否正在侦听端口。(请注意,该-b选项需要管理员权限。我使用“以管理员身份运行”打开命令窗口。)
回答by Ishwar Pohani
If you are using windows os then replace line in tomcat configuration Tomcat6\bin\startup.bat.
如果您使用的是 windows 操作系统,则替换 tomcat 配置中的行Tomcat6\bin\startup.bat。
Replace
代替
call "%EXECUTABLE%" start %CMD_LINE_ARGS%
with
和
call "%EXECUTABLE%" jpda start %CMD_LINE_ARGS%
回答by Abdelhameed Mahmoud
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:
如果您需要调试在 Tomcat 上运行的应用程序,请确保您的Tomcat-folder/bin/startup.bat(如果使用 Windows)包含以下几行:
set JPDA_TRANSPORT="dt_socket"
set JPDA_ADDRESS=8000
call "%EXECUTABLE%" jpda start %CMD_LINE_ARGS%
回答by sce
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.
我在 Ubuntu 上运行 Tomcat 时遇到了问题。问题是启用了 selinux 并且由于某种原因它不会让 Eclipse 连接到调试端口。禁用 selinux 或将其置于许可模式为我解决了这个问题。

