11

Eclipse is showing Cannot connect to VM error while i opened any Program in debug mode.. Here is Exception stack

 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. dont know which socket is closed in my PC.Kindly help me..I am using eclipse 8.x

0

12 Answers 12

15

This is because of the localhost setting in your machine. check your ip against localhost in hosts file in /etc folder

3
  • This worked for me. On MacOs 10.10 I looked up my IP in System Preferences -> Network and then put the line 'localhost <MyIpAdress>' in the file /etc/hosts. Also I commented out other lines mentioning localhost.
    – user152468
    Jan 5, 2015 at 13:22
  • Worked for me, even though I expected the answer to be something much more complicated. Surprisingly, my /etc/hosts entry had somehow previously changed to "127.0.0.1localhost" (no intervening space), and fixing that immediately fixed Eclipse's probably with debug. So, folks, take a look at this answer even if you think the real problem must be something trickier.
    – mlibby
    Mar 23, 2016 at 12:47
  • I can't believe this actually worked! I had duplicate "::1 localhost localhost.localdomain" lines in my /etc/hosts file. Commenting out the duplicate line got it working.
    – fred271828
    Aug 31, 2016 at 12:41
3

adding 127.0.0.1 localhost to /etc/hosts, solved this very same problem on my mac !

2

Adding the following to the eclipse.ini file make this issue resolve:

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

Here's my eclipse.ini file:

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

If you are a MAC user use following steps

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

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"

0

I encountered this problem using Springsource's version of eclipse. My problem was that my Debug Configuration was defined to use the Javascript debugger, and I was trying to debug a Java program.

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.

0

The easiest way to solve the problem:

  1. Select "Debug Configurations" enter image description here
  2. Select the "Arguments"-Tab enter image description here
  3. Remove the argument "--add-modules=ALL-SYSTEM" enter image description here
  4. Then "Apply" and "Debug".
0

one of the basic solution is

when your creating new project uncheck the box "create module-info.java file"

(click next next finish)enter image description here

0

Right click your project name, then select Build Path->Configure Build Path. Click on the Libraries tab and check if your libs (especially Tomcat libs) are under "Modulepath" and not "Classpath". In my case, my project needs Tomcat libs. When I put Tomcat libs under "Classpath", it does not work. When I move the libs to "Modulepath", it works.1

0

I my case on Windows 10 machine it was the wrong JRE selected for the project causing the error.

Only the default JRE installed in the user's home directory was initially listed (in Eclipse - Window->Preferences->Java->JRE). I have added two other JREs.

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

Afterwards debugging started to work just fine.

0

Deleting my module-info.java file solved the problem for me.

-1

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.

     -Xdebug -Xrunjdwp:transport=dt_socket,address=8453,server=y,suspend=n
4
  • 1
    even i am getting the error for simple java program..Even i am trying to print hello world..But only in debug mode not in Run mode
    – Arun
    Oct 5, 2012 at 18:40
  • How are you running your simple program in debug mode? Are you using eclipse option "debug as" or doing something different? Oct 5, 2012 at 18:44
  • Yes i put a breakpoint and run in debug mode as debug as-->my JavaFile Name
    – Arun
    Oct 5, 2012 at 18:47
  • Try restarting your Eclipse with clean option as eclipse -clean and see. Oct 5, 2012 at 19:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.