简体   繁体   English

Eclipse 在调试模式下启动时显示无法连接到 VM 错误

[英]Eclipse when launching in debug mode show Cannot connect to VM error

Eclipse is showing Cannot connect to VM error while i opened any Program in debug mode.. Here is Exception stack当我在调试模式下打开任何程序时,Eclipse 显示无法连接到 VM 错误..这是异常堆栈

 java.net.SocketException: socket closed
    at java.net.PlainSocketImpl.socketAccept(Native Method)  //I dont know which socket is closed in my PC
    at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:384)
    at java.net.ServerSocket.implAccept(ServerSocket.java:453)
    at java.net.ServerSocket.accept(ServerSocket.java:421)
    at org.eclipse.jdi.internal.connect.SocketTransportService.accept(SocketTransportService.java:95)
    at org.eclipse.jdi.internal.connect.SocketTransportImpl.accept(SocketTransportImpl.java:56)
    at org.eclipse.jdi.internal.connect.SocketListeningConnectorImpl.accept(SocketListeningConnectorImpl.java:135)
    at org.eclipse.jdt.internal.launching.StandardVMDebugger$ConnectRunnable.run(StandardVMDebugger.java:107)
    at java.lang.Thread.run(Thread.java:619)

Even my Localhost is working fine,i pinged 127.0.01 and localhost both is working fine,Even i restarted my PC even getting the same error.即使我的本地主机工作正常,我 ping 127.0.01 和 localhost 都工作正常,即使我重新启动我的电脑,甚至出现相同的错误。 dont know which socket is closed in my PC.Kindly help me..I am using eclipse 8.x不知道我的 PC 中关闭了哪个套接字。请帮助我..我正在使用 eclipse 8.x

This is because of the localhost setting in your machine.这是因为您机器中的 localhost 设置。 check your ip against localhost in hosts file in /etc folder在 /etc 文件夹中的主机文件中根据本地主机检查您的 IP

127.0.0.1 localhost添加到 /etc/hosts,在我的 mac 上解决了同样的问题!

Adding the following to the eclipse.ini file make this issue resolve:将以下内容添加到eclipse.ini文件可解决此问题:

-vm
C:\Program Files\Java\jdk1.7.0_71\jre\bin\javaw.exe (path of javaw.exe )

Make sure path of javaw.exe should be written in next line of -vm .确保javaw.exe路径应该写在-vm下一行。

Here's my eclipse.ini file:这是我的eclipse.ini文件:

-startup
plugins/org.eclipse.equinox.launcher_1.3.0.v20130327-1440.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.1.200.v20140116-2212
-product
org.eclipse.epp.package.standard.product
--launcher.defaultAction
openFile
--launcher.XXMaxPermSize
256M
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
--launcher.appendVmargs
-vm
C:\Program Files\Java\jdk1.7.0_71\jre\bin\javaw.exe
-vmargs
-Dosgi.requiredJavaVersion=1.6
-Xms40m
-Xmx512m

If you are a MAC user use following steps如果您是 MAC 用户,请使用以下步骤

sudo -su root
vi /etc/hosts
---> now insert following line and save the file opened in vi editor
127.0.0.1 localhost

one of the solution is after creating a project , "click next" , enter image description here " not finish"解决方法之一是创建项目后,“单击下一步”,在此处输入图像描述“未完成”

uncheck the box "create module-info.java file"取消选中“创建 module-info.java 文件”框

I encountered this problem using Springsource's version of eclipse.我在使用 Springsource 的 eclipse 版本时遇到了这个问题。 My problem was that my Debug Configuration was defined to use the Javascript debugger, and I was trying to debug a Java program.我的问题是我的调试配置被定义为使用 Javascript 调试器,而我正在尝试调试 Java 程序。

Solution: go to "Debug As" -> "Debug Configurations", and somewhere in that window (at the end in my case SpringSource 3.1) set the Eclipse JDT Launcher as the debugger option.解决方案:转到“Debug As”->“Debug Configurations”,然后在该窗口的某处(在我的情况下是 SpringSource 3.1 的最后)将 Eclipse JDT Launcher 设置为调试器选项。

The easiest way to solve the problem:解决问题的最简单方法:

  1. Select "Debug Configurations"选择“调试配置” 在此处输入图片说明
  2. Select the "Arguments"-Tab选择“参数”-选项卡在此处输入图片说明
  3. Remove the argument "--add-modules=ALL-SYSTEM"删除参数“--add-modules=ALL-SYSTEM” 在此处输入图片说明
  4. Then "Apply" and "Debug".然后“应用”和“调试”。

one of the basic solution is基本解决方案之一是

when your creating new project uncheck the box "create module-info.java file"创建新项目时取消选中“创建模块信息.java文件”框

(click next next finish) enter image description here (点击下一步完成)在此输入图片说明

Right click your project name, then select Build Path->Configure Build Path.右键单击您的项目名称,然后选择 Build Path->Configure Build Path。 Click on the Libraries tab and check if your libs (especially Tomcat libs) are under "Modulepath" and not "Classpath".单击“库”选项卡并检查您的库(尤其是 Tomcat 库)是否在“模块路径”而不是“类路径”下。 In my case, my project needs Tomcat libs.就我而言,我的项目需要 Tomcat 库。 When I put Tomcat libs under "Classpath", it does not work.当我将 Tomcat 库放在“类路径”下时,它不起作用。 When I move the libs to "Modulepath", it works.当我将库移动到“Modulepath”时,它可以工作。 1 1

I my case on Windows 10 machine it was the wrong JRE selected for the project causing the error.我在 Windows 10 机器上的情况是为导致错误的项目选择了错误的 JRE。

Only the default JRE installed in the user's home directory was initially listed (in Eclipse - Window->Preferences->Java->JRE).最初只列出了安装在用户主目录中的默认 JRE(在 Eclipse - Window->Preferences->Java->JRE 中)。 I have added two other JREs.我添加了另外两个 JRE。

Next I went into the project, selected the package I wanted to debug, went to the "Debug Configurations" and selected one of the freshly added JRE (in my case Java15).接下来我进入项目,选择我想调试的包,进入“调试配置”并选择一个新添加的 JRE (在我的例子中是 Java15)。

Afterwards debugging started to work just fine.之后调试开始工作得很好。

删除我的module-info.java文件为我解决了这个问题。

You need to start you server with debug port enabled and connect the debugger with the server using the same port.您需要在启用调试端口的情况下启动服务器,并使用相同端口将调试器与服务器连接。

For "Tomcat" server, you can add the following to start it in debug mode with debug port as 8453 .对于“Tomcat”服务器,您可以添加以下内容以调试模式启动它,调试端口为8453

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM