270

I'm getting the following error when I try to run a simple JSP program on Tomcat in Eclipse.

Several ports (8005, 8080, 8009) required by Tomcat v6.0 Server at localhost are already in use. The server may already be running in another process, or a system process may be using the port. To start this server you will need to stop the other process or change the port number(s).

How is this caused and how can I solve it?

BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
elle
  • 3,055
  • 6
  • 22
  • 22
  • I had a similar issue which turned out to be the windows firewall. – James Oravec Oct 27 '15 at 22:17
  • Probably some undead process is keeping your tomcat alive. kill the process either by finding its ID and terminating it or by restarting your machine. – Felipe Leão Jan 15 '19 at 18:07
  • you can use these command to stop the tomcat services already running from the command console. `netstat -ano | findStr 8080` to find the running services and then find the process id and copy the pid and run the command again as `taskkill /F /PID pid_number` – Mdhar9e Aug 02 '19 at 15:22

35 Answers35

482

You've another instance of Tomcat already running. You can confirm this by going to http://localhost:8080 in your webbrowser and check if you get the Tomcat default home page or a Tomcat-specific 404 error page. Both are equally valid evidence that Tomcat runs fine; if it didn't, then you would have gotten a browser specific HTTP connection timeout error message.

You need to shutdown it. Go to /bin subfolder of the Tomcat installation folder and execute the shutdown.bat (Windows) or shutdown.sh (Unix) script. If in vain, close Eclipse and then open the task manager and kill all java and/or javaw processes.

Or if you actually installed it as a Windows service for some reason (this is namely intented for production and is unhelpful when you're just developing), open the services manager (Start > Run > services.msc) and stop the Tomcat service. If necessary, uninstall the Windows service altogether. For development, just the ZIP file is sufficient.

Or if your actual intent is to run two instances of Tomcat simultaneously, then you have to configure the second instance to listen on different ports. Consult the Tomcat documentation for more detail.

BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
  • 1
    perfect, this has been plaguing me forever. I executed it as `sh shutdown.sh` in terminal within the /bin directory. – Danny Englander Sep 07 '12 at 22:21
  • 2
    Hello BalusC, I like you ! There is no `shutdown.bat` in my bin folder. Tomcat was installed as a service and not as a zip. Stopping tomcat service in services fixed the problem. Thanks. Chenqui. – Erran Morad Apr 26 '14 at 05:01
  • 1
    @Borat: You're welcome. Keep in mind that you'd really better uninstall the service and get the zip instead. – BalusC Apr 27 '14 at 12:57
  • Or other software is using those ports (ex: Skype) – Vũ Ngô Aug 04 '14 at 09:48
  • @BalusC: I'm a complete newb here, so this might not make sense, but here's what's in my head when you say that: what *if I want to use that instance of tomcat you're telling me to shut down*. (I.e, how do I configure to use that tomcat instance? How do I publish to it?) – Jay Sullivan Feb 06 '15 at 03:23
  • @notfed: let it listen on a different port. See also last paragraph of the answer. – BalusC Feb 06 '15 at 08:19
  • use sudo service tomcat7 shutdown to stop the service in linux system and then open the eclipse then start the tomcat7. It will work. – loyola May 05 '15 at 05:24
  • 6
    "kill all java and/or javaw processes" worked for me, thanks. – Thariq Nugrohotomo Nov 18 '15 at 02:38
  • 3
    Opening the `system monitor` or `task manager` and killing a java process which is using `about 400 MB` or more `RAM` will also solve the problem. It is unknowingly reserving the process. – viper Jun 10 '16 at 07:00
  • @BalusC: Thanks. for the answer! "You've another instance of Tomcat already running." By "instance", do you mean process? So does eclipse run tomcat in a different process from the tomcat process run from command line? – Tim Dec 21 '17 at 13:58
  • Hi, I'm using spring boot and i'm getting the same issue for any ports. for me there are no java / javaw processes running. Please help. – Bandham Manikanta Apr 16 '18 at 14:53
  • @BalusC You saved me. I uninstalled the Tomcat and just used .zip file. Voila! Now I ran the first JSP program! Thanks!!!!!!!!!!!!!!!!!!!!!! – Dongkyu Choi Sep 01 '19 at 04:53
57
kill $(ps -aef | grep java | grep apache | awk '{print $2}')
  • no need to restart Eclipse
  • if you get the above error, just enter this line in terminal
  • again start the tomcat in Eclipse.
  • works only in Linux based system ( Ubuntu ..etc )
OneCricketeer
  • 126,858
  • 14
  • 92
  • 185
Shan
  • 1,619
  • 13
  • 5
  • 6
    This is better `kill $(ps -aef | grep java | grep apache | awk '{print $2}')` – firesofmay Jan 08 '13 at 20:01
  • This does not work for me (Mint 17.1). It just gives me the help for the `kill` command. – CoderGuy123 Jun 01 '15 at 02:18
  • This worked for me. However I wanted to know if I have 2 instances running and I have to force stop one using this method, how do I figure out which to shut. Thanks – Gautam Jul 26 '19 at 07:01
30

If you are running on windows try this in the command line prompt:

netstat -ano

This will show all ports in use and the process id PID # of the process that is using that port. Then Ctrl+Alt+Del and open Task Manager to see which process is that.

You can then choose either to close/stop it or configure your server to use another port. To check if the new choosen port (let's say 8010) is available do this:

netstat -ano | grep 8010

If it does not return any lines then you are fine.

To change the port go to the Server view, open server.xml and change the port there. Mine has this entry:

Connector port="8010" protocol="AJP/1.3" redirectPort="8443"
Community
  • 1
  • 1
Mau
  • 301
  • 3
  • 3
27

If you are on mac environment, here is what I did.

Find the process id running on this port from terminal, eg, 8080:

lsof -i :8080

and kill it:

kill -9 <PID>  

Example:

You may see following result:

MacSys:bin krunal.$ lsof -i :8080

COMMAND   PID     USER   FD   TYPE     DEVICE  SIZE/OFF   NODE  NAME
java     21347   krunal  52u  IPv6      XXX      0t0      TCP  *:http-xxx (LISTEN)

and kill it: (kill -9 21347)

Krunal
  • 68,602
  • 40
  • 230
  • 241
Timeless
  • 6,444
  • 8
  • 54
  • 90
21

Steps to free port which is already used to run tomcat server in Eclipse

For example , suppose 8080 port is used , we need to make free 8080 to run tomcat

Step 1:

C:\Users\username>netstat -o -n -a | findstr 0.0:8080

TCP 0.0.0.0:3000 0.0.0.0:0 LISTENING 3116

Now , we can see that LISTENING port is 3116 for 8080 ,

We need to kill 3116 now

Step 2:-

C:\Users\username>taskkill /F /PID 3116

Step 3: Go to Eclipse and start Server , it will run

Sachindra N. Pandey
  • 1,029
  • 16
  • 15
16

If you use Eclipse then double click on servers and double click on tomcat server then one file will open. In that file change HTTP port to some other port number and save(Ctrl+S) then again start the server.

Elrond_EGLDer
  • 47,430
  • 25
  • 189
  • 180
abc
  • 161
  • 1
  • 2
  • This worked for me while the other solutions did not. I'm using Mint 17.1. I had to install tomcat both thru Eclipse and thru apt-get because I could not find the folder where apt-get installed it. So that's presumably why I have two. Still I could not close the first one with the kill commands. – CoderGuy123 Jun 01 '15 at 02:22
12

If Eclipse says

Several ports (8005, 8080, 8009) required by Tomcat v6.0 Server at localhost are already in use

This error comes because tomcat may be running in background so first stop that server..follow the below details.

Solution is:

  1. Open the "console" view (window->show view->Console)
  2. Then stop the tomcat server.
  3. Then open the "server" view and start the server it will work.

Thanks!

Naveed S
  • 4,672
  • 4
  • 32
  • 49
Ashu Phaugat
  • 577
  • 8
  • 21
10

I have no another instance of Tomcat running ad no other process using "Tomcat port" (in my case, the 8088 port). Eclipse send the same message on starting Tomcat:

....The server may already be running in another process, or a system process may be using the port. To start this server you will need to stop the other process or change the port number(s).

I solve the problem in this way:

  • go to bin of tomcat by prompt
  • launch startup.bat
  • launch shutdown.bat
  • start tomcat by Eclipse
giocorito
  • 101
  • 1
  • 2
  • 1
    My problem was that 8005 and 8009 ports were busy, however 8080 port was free and no tomcat installation was running at that time. Your solution helped me to fix this issue, thanks. – Benas Feb 06 '15 at 11:48
7

What I did after reading all the suggested answer and as I know my port was already in use. I double clicked on Tomcat under the Servers tab in eclipse and it opened overview information and then find port information. Just changed conflicting port as mine was 8009 port (error mentioned during starting the server). I have changed it to 8008 and it works fine. Give a try if the changed port would not be in use server will start.

DeVilCry2ME
  • 71
  • 1
  • 1
7

Step 1: netstat -a -o -n and it will bring up a network list,search for the local address like 127.0.0.1:8080 and note the PID (eq 3624)

C:\>netstat -a -o -n

Step2 : taskkill /F /PID 3624 . Run this command to kill that process.

C:\>taskkill /F /PID 3624

link to post

Sandeep Bhardwaj
  • 1,132
  • 16
  • 22
6

On Windows use command for stopping the already running tomcat instance and try running it again in eclipse, it may work.

net stop tomcat7 

Or you can change the port in server's XML if you just want to run on some other ports.

v8-E
  • 897
  • 2
  • 14
  • 19
Gauranga
  • 776
  • 6
  • 15
4

Easy way to solve your problem:

The server may already be running in another process, or a system process may be using the port. In order to kill that port, do the following:

1) Download TCPView(only 285kb) from following link.

http://technet.microsoft.com/en-in/sysinternals/bb897437.aspx

2) Extract folder and start TCPView application.

3) Right click on java.exe(because 8009,8005 ports are commonly used by java process) and select End Process option.

this would stop another process easily..

NOTE: Running TOMCATPATH/bin/shutdown.bat may not shutdown Tomcat when it contains some demon or unmanaged threads. In such cases TCPView works fine without any issues.

shivadarshan
  • 766
  • 2
  • 11
  • 20
2

Sometimes if the ports are not freed even after attempting shutdown.bat what @BalusC suggested,you can kill the javaw process. Do following steps :

  1. Click on Start Menu and open "Windows powershell"
  2. Right click before opening and select "Run as administrator"
  3. Enter command ps. You may see a image as follows : Powershell showing current proesses running

  4. See the process number of process "javaw".The process number is the rightmost number in the columns, I have highlighted in the image process number of javaw for example.

  5. Enter command kill . javaw is killed and now you must be able to run the program.

Tiny Jaguar
  • 313
  • 3
  • 10
  • 27
2

Here's one more option to try if none of the efforts above helped. You might be using Eclipse from a Shared Drive (for eg, H:). If so, move/copy it the entire Eclipse directory to C: and try again.

My Eclipse could not open ports for Tomcat server (with the above error), nor even connect to internet. I also tried another Tomcat plugin (Sysdeo) which failed to open the ports too.

These are the options I tried:

Check and Kill Other Tomcat Instances

  • In command prompt, netstat -ano and check if any other processes are using the conflicted ports.
  • Find the PID and kill it
  • Try starting the server again.

Change Tomcat Ports in Eclipse

  • In Eclipse Server tab, double click the Tomcat instance. This will open the configuration tab.
  • Under Ports, change the port numbers. (for eg, 18080).

Kill java.exe and javaw

See my other answer for Eclipse not connecting to Internet (https://stackoverflow.com/a/37246087/4212710).

Community
  • 1
  • 1
typoerrpr
  • 1,408
  • 17
  • 16
2

For windows users:

Go to Task Manager directly with CTRL+SHIFT+ESC key combination.

Kill the "java.exe" processes by right clicking and selecting "End Task".

Arif Acar
  • 1,140
  • 2
  • 13
  • 28
2

I checked all the answers but informing only to kill PID.

In case if you have terminal access shared by all it will not help or maybe you do not have permission to kill PID.

In this case what you can do is:

Double click on server

Go to Overview and change ports in Ports like this:

enter image description here

v8-E
  • 897
  • 2
  • 14
  • 19
2

If you are in Java EE prospective in Eclipse and trying to start the Tomcat Server in Eclipse in debug mode, then you will get such errors. You must switch to debug prospective in Eclipse. I have solved my problem like this.

Jitendra
  • 21
  • 1
1

The simpler fix that works for me is deleting my current deployed webapps from tomcat through the "Server" tab. Once I remove them the problem goes away. Simply re-deploy your project by going on Run As > Run on Server.

Felipe Leão
  • 885
  • 1
  • 14
  • 26
1

The problem often arises when Apache Tomcat fails to terminate, properly, even though a shutdown instruction was sent. In my case, using Tomcat 8, this happens with annoying regularity. Luckily, you can use Windows PowerShell and the netstat command to create a simple script to kill the process.

The following PowerShell script will parse the output from netstat to find any process that is listening on 127.0.0.1:8005, extract its PID and then kill that process:

netstat -a -o -n `
 | select -skip 4 `
 | % {$a = $_ -split ' {3,}'; New-Object 'PSObject' -Property @{Original=$_;Fields=$a}} `
 | ? {$_.Fields[1] -match '127\.0\.0\.1\:8005$'} `
 | % {Write-Host "Killing PID" $_.Fields[4] "..."; taskkill /F /PID $_.Fields[4] }

If your server.xml configures Tomcat to use a different port or IP, edit the regular expression on the script's fourth line accordingly.

Finally, I should point out that the situation is better on Linux because you can instruct Tomcat to save its PID to a file at startup-time and use a switch to force the shutdown, later - the shutdown script for 'nix systems already features the ability to kill the process and the sleuth-work with netstat is not required.

Xharlie
  • 1,918
  • 3
  • 13
  • 32
1

If the above issue occurs in Windows 7 or 10 based OS, the problem occurs because Tomcat is running as Windows Service. To stop Tomcat running as Windows Services, Open Windows Control Panel. Find the service "Apache Tomcat" and Stop it. The Another way is to kill the process running on port 8080 using cmd.

Open cmd running it as administrator.

  1. C:\users\username>netstat -o -n -a|findstr 0.0:8080
  2. TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING 2160.
  3. The above 2160 is process id of process running on port 8080 and kill that process using the following command
    C:\users\username>taskkill /F /PID 2160
  4. Go to IDE and start Server, it will run
1

It may be because you are not stopping your tomcat service properly. To do that, Open your task manager there you can see a javaw.exe service. First stop that service. Now restart your tomcat it works fine.

Ram Thota
  • 411
  • 4
  • 9
1

In my case, it was giving me the error: Port 8005 required by Tomcat v8.0 Server at localhost is already in use

I changed 8005 port in apache-tomcat-8.0.39\conf\server.xml but changes were not getting reflected. Then I did these changes from eclipse. by double clicking server and modifying the port from 8005 to 8006 and it works. enter image description here

Before putting 8006 I checked in windows shell if this port is available or not. By executing following command:

netstat -a -o -n | findstr 8006
Tahir Akram
  • 3,134
  • 11
  • 47
  • 65
1

I face the same problem and after searching the answer as shown below: 1. open Monitor Tomcat as shown below: enter image description here

  1. Simply press stop as shown in below picure:

enter image description here

Finally it works with me after many trials and suggested solutions.

Best Regards, Kerelos Mikhail

Kerelos
  • 65
  • 4
0

On Eclipse make a raw delete of Tomcat configuration folder under project "Servers". I tried it as last hope and it worked.

giocorito
  • 101
  • 1
  • 2
0

In case of windows, I experienced a new stuff... stopping tomcat from /bin folder will immediately not releasing the port 8080. It takes around 5-10 mins to release the port. After 10 mins again if i try to run my project Run-> Run on server .. it allows to run.

I'm unsure whether my understanding is correct!

Laxman
  • 11
  • 2
0

Several ports (8005, 8080, 8009) required by Tomcat vX.X Server at localhost are already in use

To check whether another instance of Tomcat already running or some other process is using the ports you can use:

netstat -b -a in command prompt for windows. This lists the ports in use and gives you the executable that's using each one. You need to be in the admin group to do this.

You might get something like this:

TCP 192.168.0.1:8009 192.168.0.1:0 LISTENING 196 [Tomcat7.exe]

TCP 192.168.0.1:8080 192.168.0.1:0 LISTENING 196 [Tomcat7.exe]

TCP 192.168.0.1:8005 192.168.0.1:0 LISTENING 196 [Tomcat7.exe]

Open task manager Ctrl+Shift+Esc, and kill Tomcat7.exe or any other process using these ports.

Community
  • 1
  • 1
Zeeshan
  • 9,465
  • 14
  • 65
  • 93
0

It occurs when others in the project are also using the same port numbers as you are using! double click tomcat server, change port numbers to anything 8585 or whatever. The code will now begin to run!

Shivendra
  • 1,416
  • 2
  • 21
  • 35
0

How to kill a windows service using PID -

  1. open command prompt and type netstat -ano
  2. find the PID of the ports which are in used, in this case, it will be 8080, 8005,8009. Let's say PID of these ports are 5760.
  3. Now Type taskkill /f /pid 5760
  4. it will close the PID and ports will be available for use. Now you can start tomcat as normal by Windows services or by eclipse itself.

Thanks

kill a Windows service that's stuck on stopping or starting

0

Your Tomcat is probably running already. That's why you have got an error. I've had the same problem before. I solved it very simply:

  1. Restart your computer
  2. Open Eclipse
  3. Run your Tomcat

That's all.

pacholik
  • 7,596
  • 8
  • 43
  • 50
Purgoufr
  • 463
  • 6
  • 18
0

In windows OS do right click on task bar-->start task manager-->process then check java.exe or javaw is running if it is running,then click on it and do end process then restart your tom cat server.

  1. some times skype will occupy port 80 in that case change the skype settings and put 81 for skype or change tomcat configuration.
Vasundhara
  • 87
  • 1
  • 8
0

Don't need to close your eclipse IDE.Your Tomcat is probably running already. That's why you have got an error.

open tomcat directory >> bin >> from command terminal (in my case is tomcat9)

Enter command

./shutdown.sh

it will close your running tomcat

enter image description here

Kamran
  • 584
  • 4
  • 8
0

Easiest solution

Single line command for killing multiple ports:

kill $(lsof -t -i:8005,8080,8009) 

8005, 8080 and 8009 are the ports to be freed.

Alternatively, you can try sudo kill sudo lsof -t -i:8005 in linux.

Abhijith Sasikumar
  • 4,490
  • 4
  • 24
  • 37
0

All of above do not work for me.

What I found was click the Details button. enter image description here

Then following the Multiple contexts with the same path error running web service in Eclipse using Tomcat

Removed the duplicated line then I got an another error.

The server cannot be started because one or more of the ports are invalid. Open the server editor and correct the invalid ports.

Following Can't start tomcatv9.0 in Eclipse

Then it works.

Hello
  • 618
  • 1
  • 11
0

Macbook solution:

Step 1: stop the server running Java :

Open Activity Monitor by going to Applications > Utilities > Activity Monitor. Or simple press CMD + Spacebar and start typing Activity Monitor. Look for process running Java and kill it by giving the following command in Terminal

kill -STOP <PID> 

where PID is the process ID of the Java process as displayed in the Activity Monitor. Do it a couple of times and close and reopen Activity Monitor to check Java isn't running.

Step 2: change the port :

right-click on the server in Eclipse and click 'Open'. Change port number from 8080 to 8081 or something greater in value.

This should hopefully start your server.

kush
  • 127
  • 1
  • 4
0

Refer to the following blog "how to kill tomcat without have to restart your computer"

http://stanicblog.blogspot.fr/2012/01/how-to-kill-apache-tomcat-without.html

Hope this will help someone in the future.

Shobhit Puri
  • 24,785
  • 8
  • 89
  • 115
Edmund Ng
  • 115
  • 1
  • 8
  • 1
    The link above is dead. This one points to the good blog article : http://stanicblog.blogspot.fr/2012/01/how-to-kill-apache-tomcat-without.html – dounyy Sep 26 '13 at 12:24
  • Please do not add links to read without mentioning important part. Because People are here get answers. – Menuka Ishan Nov 26 '15 at 13:00