When developing through Netbeans in Java (my personal favourite) you may come across the annoying error now and again which is telling you that Tomcat cannot start due to the port being in use already. Often this is Port 8005 but it could be something else depending on how you have things configured. Either way, this ‘feature’ is rather annoying and requires a couple of steps to kill this off and get you back on track. Unfortunately the traditional IT solution doesn’t work in this scenario, turning Netbeans off and back on again, the issue persists.
This issue is caused when you are trying to run multiple applications simultaneously and something has got in a bit of a mess in the background.
Thankfully, the solution is rather simple when you know where to look on Windows, there are a few steps involved.
Find the PID (Process ID) that is hogging the Port 8005 that you need
To do this, either search for “Resource Monitor” in the Windows start menu, or, type at the command prompt, resmon.exe. Either way will open the resource monitor as you can see in the screenshot below. Look through the list of Ports and find the port that is being blocked, then look across to the PID column to find the Process ID, you’ll need this in the next step.
For those of you more familiar with the command line, just run the following command;
Netstat –a –o –n
Netstat is a command-line tool for displaying network statistics including displaying connections using the TCP/IP protocol, i.e. your application.
The –a flag displays all connections and listening ports
The –o flag displays the owning process ID associated with each connection
The –n flag displays addresses and port numbers in numerical form
Next Force Kill the Process
To do this, you need to run Command Prompt as an Administrator. This will not work as a standard Windows user, you need to be an Administrator. Simply type;
Taskkill /F /PID 12345 (replace the process ID that you found earlier)
Done. You’re good to go again.