首个JEE项目无法运行:Tomcat 9.0端口占用问题求助
Hey there, let's work through this port occupancy issue together—since you've already sorted out the HttpServlet resolution problem, we can dive straight into getting those ports free for your Tomcat 9.0 server. Here are some actionable steps to try:
1. Double-Check You Modified the Correct server.xml File
It's easy to edit the wrong server.xml by accident! Eclipse maintains its own copy of the server config for each server instance, not the one in your Tomcat installation directory. To confirm:
- In Eclipse's Servers view, right-click your Tomcat 9 server and select
Open. - Locate and verify the three port entries are updated to unused values:
- Shutdown port:
<Server port="8006" shutdown="SHUTDOWN">(changed from 8005) - HTTP connector:
<Connector port="8081" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443"/>(changed from 8080) - AJP connector:
<Connector port="8010" protocol="AJP/1.3" redirectPort="8443"/>(changed from 8009)
- Shutdown port:
- Save the file before restarting the server.
2. Kill Stuck Tomcat Processes
Sometimes Tomcat processes linger in the background even after you stop the server in Eclipse, holding onto the ports. Here's how to find and end them:
Windows:
- Open Command Prompt and run:
netstat -ano | findstr :8080 netstat -ano | findstr :8009 netstat -ano | findstr :8005 - Note the PID number next to each port, then open Task Manager → Details tab, find the
java.exe/javaw.exeprocess with that PID, and end it.
Linux/macOS:
- Open Terminal and run:
lsof -i :8080 # Replace port number to check others - Use the PID from the output to kill the process:
kill -9 <PID>
3. Reset Eclipse Server Configuration
Eclipse's publish settings might be overwriting your port changes. Try these steps:
- Right-click your Tomcat server in the Servers view →
Clean. - Then right-click again →
Publish→Clean. - Restart the server and check if the port error is gone.
4. Check for Other Port-Using Applications
These common ports might be grabbed by other software:
- 8080: Often used by other web servers (Apache, Nginx), proxy tools, or even some IDEs.
- 8005/8009: Could be used by older Tomcat instances, Java services, or monitoring tools.
Use the port-check commands from step 2 to identify any non-Tomcat processes using these ports and close them.
5. Create a Fresh Tomcat Server Instance
If all else fails, the existing server instance might have corrupted configs:
- Delete your current Tomcat server from the Servers view (right-click →
Delete). - Go to
File→New→Server, select Tomcat 9.0, and set up a new instance. - Update the port numbers in the new instance's
server.xmlas before, then reattach your project viaProject > Properties > Targeted Runtime.
内容的提问来源于stack exchange,提问作者tech_logman

