eclipse 无法连接到远程 VM。拒绝连接。在尝试调试 jar 时

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11027073/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 18:22:24  来源:igfitidea点击:

Failed to connect to remote VM. Connection refused. while tring to debug jar

eclipsedebuggingremote-debugging

提问by shraddha

I am trying to debug the jar file with Remote JAVA Application debug. I am getting 'Failed to connect to remote VM. Connection refused.' error following is stack trace..

我正在尝试使用远程 JAVA 应用程序调试来调试 jar 文件。我收到“无法连接到远程虚拟机”的消息。拒绝连接。' 以下错误是堆栈跟踪..

java.net.ConnectException: Connection refused: connect at java.net.DualStackPlainSocketImpl.connect0(Native Method) at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:69) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391) at java.net.Socket.connect(Socket.java:579) at java.net.Socket.connect(Socket.java:528) at java.net.Socket.(Socket.java:425) at java.net.Socket.(Socket.java:208) at org.eclipse.jdi.internal.connect.SocketTransportService$2.run(SocketTransportService.java:136) at java.lang.Thread.run(Thread.java:722)

java.net.ConnectException:连接被拒绝:连接在 java.net.DualStackPlainSocketImpl.connect0(Native Method) at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:69) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java: 339) 在 java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200) 在 java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182) 在 java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157) 在 java. net.SocksSocketImpl.connect(SocksSocketImpl.java:391) at java.net.Socket.connect(Socket.java:579) at java.net.Socket.connect(Socket.java:528) at java.net.Socket.( Socket.java:425) 在 java.net.Socket.(Socket.java:208) 在 org.eclipse.jdi.internal.connect.SocketTransportService$2。在 java.lang.Thread.run(Thread.java:722) 运行(SocketTransportService.java:136)

采纳答案by Nicholas DiPiazza

Did you remember to enable debugging on the JVM you are trying to connect to? This is done through JAVA_OPTS when you run the remote JVM.

您是否记得在您尝试连接的 JVM 上启用调试?这是在运行远程 JVM 时通过 JAVA_OPTS 完成的。

For example, to add debugging to tomcat, you would add these JAVA_OPTS when launching the java process:

例如,要给tomcat添加调试功能,你需要在启动java进程时添加这些JAVA_OPTS:

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

回答by committedandroider

If anyone else is observing this behavior and have checked their Java command line arguments, port number and hostname, I was able to fix this issue by restarting Eclipse.

如果其他人观察到这种行为并检查了他们的 Java 命令行参数、端口号和主机名,我可以通过重新启动 Eclipse 来解决这个问题。

回答by Puneet Lamba

Make sure you're adding the debug flags BEFORE the reference to your Java program, otherwise they will be passed to the program itself rather than to Java.

确保在引用 Java 程序之前添加调试标志,否则它们将传递给程序本身而不是 Java。

Also, 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.

此外,Eclipse 有时会很奇怪,当您运行“调试配置”时它不会自动切换到“调试”透视图。成功建立调试会话后,如果您再次运行它,认为它没有运行和/或静默失败,则会收到错误消息:“无法连接到远程 VM。连接被拒绝。” 因此,始终切换到“调试”透视图以查看发生了什么。