简体   繁体   中英

How do I resolve the "java.net.BindException: Address already in use: JVM_Bind" error?

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.

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>

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.

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

 taskkill -pid 431 /f

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.

In Mac:

Kill process Terminal: kill <pid>

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

From Diego Pino answer

(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

在此处输入图片说明

For windows :

  1. Find the process id

    netstat -nao | find "8080"

It will show you the process ID as a number.

Example :

TCP    0.0.0.0:8080           0.0.0.0:0              LISTENING       18856

Here 18856 is the process ID

  1. Kill that process

    taskkill /PID 18856 /F

Output : SUCCESS: The process with PID 18856 has been terminated.

Here using taskkill you are killing the process ID :18856

For linux/Mac :

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

Here you are find the process using sudo lsof -t -i:8080 and killing it by sudo kill command

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.

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

在此处输入图片说明

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.

如果您是 linux 用户,则需要关闭端口,然后键入

fuser -k 8080/tcp

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.

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

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.

截图供参考。

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.

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.

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.

(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

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.

You can close every Java Process and start again your app:

taskkill /F /IM java.exe

start your app again...

This BindException would come when another process is already running in the specified port(8080).

You can use anyone of the following approach.

  1. Change the server port: If you are using Tomcat server and IntelliJ IDE, you can configure the server port by configuring the tomcat server

    在此处输入图片说明

or

  • Go to tomcat>conf folder
  • Edit server.xml
  • Search "Connector port"
  • Replace "8080" by your port number
  • Restart tomcat server.
  1. Kill the existing running process in that port and start the server.

For Linux/Mac

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

For Windows

 netstat -ano | findstr :8080 taskkill /PID typeyourPIDhere /F

Note: (/F forcefully terminates the process)

I actually just used the Terminate button in Console Tab. It's a small red box. Hope that hepls.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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