Ubuntu环境运行Java项目报错:Tomcat端口被占用求助
Hey, I know that port conflict error can be super frustrating when you're trying to fire up your Tomcat server in STS on Ubuntu. Let's walk through two reliable ways to fix this:
1. Kill the Process That's Hogging the Ports
This is the quickest fix if you don't need the other process running. Here's how to do it via the terminal:
- First, find the PID (process ID) of the program using port 8005:
Run either of these commands:sudo lsof -i :8005sudo netstat -tulpn | grep :8005
Look for the number in thePIDcolumn of the output—this is what we need to terminate. - Kill the process with:
sudo kill -9 <your-PID-here>
Replace<your-PID-here>with the actual number you found (e.g.,sudo kill -9 1456). - Repeat the same steps for port 8080 just to be safe—swap out the port number in the commands above.
2. Change Tomcat's Port Numbers (If You Don't Want to Kill the Other Process)
If the process using those ports is something you need to keep running, just reconfigure Tomcat to use different ports:
- In STS, locate your Tomcat server in the「Servers」tab. Right-click it and select Open.
- In the server configuration window, scroll down to the「Ports」section. You'll see:
- Shutdown port: 8005
- HTTP/1.1: 8080
- Change these to unused port numbers—common alternatives are 8006 (for shutdown) and 8081 (for HTTP). Feel free to pick any other ports that aren't in use.
- Save the configuration, then restart your Tomcat server. It should start up without the port conflict error.
A quick tip: If killing the process doesn't work, double-check if Tomcat might still be running in the background (sometimes it doesn't shut down cleanly). You can also use sudo lsof -i :8080 again to verify the port is free before restarting.
内容的提问来源于stack exchange,提问作者jeslin
相关产品推荐
相关产品推荐

