214

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.

Caffeinated
  • 10,270
  • 37
  • 107
  • 197
  • 1
    I have seen this often on development machines when you are running trials of code -- How may the problem be avoided? – will May 01 '15 at 14:42
  • http://www.srikanthtechnologies.com/blog/java/changeglassfishport_4.1.aspx – jjoselon Sep 10 '19 at 00:37

20 Answers20

219

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>

biniam
  • 7,518
  • 6
  • 42
  • 52
Diego Pino
  • 9,928
  • 1
  • 48
  • 52
  • 4
    Yes, that's linux. Then try something equivalent in Windows. Maybe this can help: http://stackoverflow.com/questions/15708/lsof-equivalent-for-windows – Diego Pino Oct 04 '12 at 23:26
  • 1
    so I am using Raspbian and it says : bash: lsof : command not found. any suggestions? – Mona Jalal Jan 21 '16 at 02:34
  • 1
    @MonaJalal hmmm not sure but, maybe try something like `sudo apt-get install lsof` – Caffeinated Jan 21 '16 at 02:37
  • @DiegoPino I am facing same error `java.net.BindException: Address already in use (Bind failed)` I used `lsof -i:8080` and got `tcp6 0 0 :::8080 :::* LISTEN 106872/java` . What should I do ? Kill java ?? – Avijit Barua Feb 17 '19 at 05:41
  • @AvijitBarua The process id (pid) of the java programm bound to this port is 106872. Every Java program that you launch presents itself as the program java (it is the java virtual machine that runs your compiled code). So yes, you could exit or kill this java program, if it is not some critical (system) tool, but your own program; have a look in a task manager like `htop`. Maybe you try to bind to a port used by a valid program that should not be killed. – xuiqzy Feb 27 '20 at 11:49
156

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.

informatik01
  • 15,174
  • 9
  • 67
  • 100
Guido Simone
  • 7,612
  • 2
  • 16
  • 19
  • a quick work around: Open server view > double click on the server > change the port numbers used (ie. for Tomcat admin, HTTP/1.1, & AJP/1.3) – Adrien Be Sep 27 '13 at 07:01
  • 2
    @novice_developer `netstat` is the command you are looking for, with -a and -p options, `man netstat` is your friend for all the rest :) – sox with Monica Jul 26 '17 at 20:38
  • 1
    If the above process not working then restart the PC once, I think it will work. It started working in my case. – Kumar May 16 '18 at 08:55
126

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
Abhi
  • 6,009
  • 6
  • 37
  • 52
  • 13
    netstat -ano | find "number of your port" Use this on Windows for specific port. – BlondCode Dec 28 '16 at 14:32
  • For me (using Windows 10) `find` didn't work but `findstr` did. To avoid false positives it also helps to prepend a colon, e.g. `netstat -ano | findstr :8080`. Having done this - let's say it returned a PID of 1234 - if you then want to look up the name of this process this can be done via `tasklist /fi "pid eq 1234`". – Steve Chambers Jun 29 '20 at 10:26
40

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.

Bharti Rawat
  • 1,715
  • 15
  • 30
  • I am configuring CentOs server In digital ocean. If I kill this process how can I run server again ? – Avijit Barua Feb 17 '19 at 05:54
  • Only use -9 if it your own program and you don't have any data to lose there. It uncleanly kills the process, -15 tells the programm to exit itself. – xuiqzy Feb 27 '20 at 11:53
39

In Mac:

Kill process Terminal: kill <pid>

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

From Diego Pino answer

Bharti Rawat
  • 1,715
  • 15
  • 30
Hoyin
  • 499
  • 5
  • 6
31

(Windows Only)

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

By running the command :

netstat -ano | findstr :yourPortNumber

As shown in picture below

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

taskkill /pid yourid /f

enter image description here

Sufiyan Ansari
  • 1,362
  • 15
  • 21
11

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

Md. Sajedul Karim
  • 6,263
  • 3
  • 47
  • 77
8

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.

javarebel
  • 150
  • 1
  • 9
8

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

enter image description here

Vibhav Chaddha
  • 349
  • 4
  • 14
5

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.

CharlesX
  • 128
  • 1
  • 7
5

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

fuser -k 8080/tcp
Suraj Rao
  • 28,186
  • 10
  • 88
  • 94
3

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.

Yasitha Bandara
  • 1,093
  • 1
  • 11
  • 18
2

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

Akash Yadav
  • 2,353
  • 18
  • 31
2

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.

Screenshot for the reference.

Kumar
  • 388
  • 1
  • 8
  • 18
2

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.

EnGoPy
  • 103
  • 10
0

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.

Chetan Gowda
  • 360
  • 4
  • 14
0

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.

suketup
  • 419
  • 7
  • 12
0

(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

tonysok
  • 567
  • 1
  • 6
  • 10
0

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.

Rakesh Burbure
  • 1,025
  • 12
  • 27
0

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

taskkill /F /IM java.exe

start your app again...

Anthony Piñero
  • 190
  • 1
  • 5