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?
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
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 on127.0.0.1:8005
, extract its PID and then kill that process: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.To check whether another instance of Tomcat already running or some other process is using the ports you can use:
You might get something like this:
Open task manager Ctrl+Shift+Esc, and kill
Tomcat7.exe
or any other process using these ports.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.
C:\users\username>taskkill /F /PID 2160
On Eclipse make a raw delete of Tomcat configuration folder under project "Servers". I tried it as last hope and it worked.
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!