How do I resolve the “java.net.BindException: Addr

2020-01-22 13:38发布

问题:

In Eclipse, I got this error:

run:
     [java] Error creating the server socket.
     [java] Oct 04, 2012 5:31:38 PM cascadas.ace.AceFactory bootstrap
     [java] SEVERE: Failed to create world : java.net.BindException: Address already in use: JVM_Bind
     [java] Java Result: -1
BUILD SUCCESSFUL
Total time: 10 seconds

I'm not sure why it came up now, but it ran fine just a few hours ago. Do I need to restart my machine? How do i get to the bottom of it? I appreciate any tips or advice.

回答1:

Yes you have another process bound to the same port.

TCPView (Windows only) from Windows Sysinternals is my favorite app whenever I have a JVM_BIND error. It shows which processes are listening on which port. It also provides a convenient context menu to either kill the process or close the connection that is getting in the way.



回答2:

If you know what port the process is running you can type: lsof -i:<port>.

For instance, lsof -i:8080, to list the process (pid) running on port 8080.

Then kill the process with kill <pid>



回答3:

In windows

netstat -ano

will list all the protocols, ports and processes listening . Use

taskkill -pid "proces to kill" /f

to kill the process listening to the port. e.g

 taskkill -pid 431 /f


回答4:

In Mac:

Kill process Terminal: kill <pid>

Find pid: Terminal: lsof -i:<port>

From Diego Pino answer



回答5:

In Ubuntu/Unix we can resolve this problem in 2 steps as described below.

  1. Type netstat -plten |grep java

    This will give an output similar to:

    tcp   0   0 0.0.0.0:8080   0.0.0.0:*  LISTEN   1001  76084  9488/java       
    

    Here 8080 is the port number at which the java process is listening and 9488 is its process id (pid).

  2. In order to free the occupied port, we have to kill this process using the kill command.

    kill -9 9488
    

    9488 is the process id from earlier. We use -9 to force stop the process.

Your port should now be free and you can restart the server.



回答6:

(Windows Only)

To kill a process you first need to find the Process Id (pid)

By running the command :

netstat -ano | findstr :yourPortNumber

You will get your Process Id (PID), Now to kill the same process run this command:

taskkill /pid yourid /f



回答7:

You have another process running on the same port.

You could try killing one of the java.exe services running in your task manager - ps make sure you dont kill eclipse since that is listed as java.exe as well. If nothing else works, restarting your machine will fix it anyhow. It looks like youre not shutting down a socket from a previous test. Hope this helps.



回答8:

In Windows CMD line, find out the Process ID that hold a connection on the bind port by entering following command:

C:> netstat -a -o

-a show all connections

-o show process identifier

And then Terminate the process.



回答9:

For those who are looking for the simplest of the answers (as that is what we usually miss), just stop your running project and start it again. Most of the time what we do is we forget to stop the project we ran earlier and when we re-run the project it shows such an issue.

I am also attaching a photo to make it clearer (I use 'Spring tool suite'). So what you need to do is either click the button on the extreme right, if you want to relaunch the same project or first click on the button which is 2nd from the right to stop your project and then the button on the extreme left to run your project. I hope this will solve the issue of few of the newer programmers. :)



回答10:

Yes, as Guido Simone said it because another process listening to the same port.If you are in Ubuntu You can simply kill that process giving command sudo kill $(sudo lsof -t -i:[port number])

ex: sudo kill $(sudo lsof -t -i:8080)

But once it didn't work for me. i gave the command

$ lsof -i:[port] 

and it shows nothing.

I checked my docker containers using command docker ps -a but non of them alive.All containers has stopped (but i remember ,i stopped one container which was used same port few minutes ago.).To make sure that docker is not the reason,I stop whole docker process using command sudo service docker stop and try again. Surprisingly eclipse didn't show the error at that time .It run my program perfectly.

Hope my experience will help some one.



回答11:

The port is already being used by some other process as @Diego Pino said u can use lsof on unix to locate the process and kill the respective one, if you are on windows use netstat -ano to get all the pids of the process and the ports that everyone acquires. search for your intended port and kill.

to be very easy just restart your machine , if thats possible :)



回答12:

Restart the PC once, I think it will work. It started working in my case. One more thing can be done go to Task Manager and End the process.



回答13:

You need to close your port if you are a linux user then type

fuser -k 8080/tcp


回答14:

In my case Tomcat was running in a background. I've installed it as a external servlet while using Eclipse. With a Spring Boot in Intellij it has it own server but cannot start while it's already occupied.
In my case Tomcat starts automatically I turn on my OS, that is why I need to shut down him manualy:

$ sudo service tomcat stop

of course "tomcat" depends what version of tomcat you are using.
Hope it might help to someone.



回答15:

I faced similar issue in Eclipse when two consoles were opened when I started the Server program first and then the Client program. I used to stop the program in the single console thinking that it had closed the server, but it had only closed the client and not the server. I found running Java processes in my Task manager. This problem was solved by closing both Server and Client programs from their individual consoles(Eclipse shows console of latest active program). So when I started the Server program again, the port was again open to be captured.



回答16:

Your port must be busy in some Other Process. So you can download TCPView on https://technet.microsoft.com/en-us/sysinternals/bb897437 and kill the process for used port.

If you don't know your port, double click on the server that is not starting and click on Open Server Properties Page and click on glassfish from left column. You will find the ports here.



回答17:

(1) check the port is in use or not, kill that process

$ lsof -i:[port]

(2) another reason is the port is used by ipv6, solution:

edit /etc/sysctl.conf

add this to the file

net.ipv6.conf.all.disable_ipv6 = 1

then make it effect

$ sudo sysctl -p /etc/sysctl.conf

or just reboot



回答18:

It means some other process is already using the port. In case if this port is being used by some other critical applications and you don't want to close that application, the better way is to choose any other port which is free to use.

Configure your application to use any other port which is free and you will see your application working.