IntelliJ+Maven配置Tomcat8.5启动JavaWeb遇Http 404错误
Hey there! Let's get to the bottom of this 404 issue—since the tomcat7:run plugin works perfectly, your Maven setup is definitely good to go. This is almost certainly a problem with how IntelliJ IDEA is deploying your project to Tomcat. Let's walk through the most common fixes step by step:
1. Double-Check the Tomcat Deployment Context Path
The most common culprit here is a mismatch between the context path IDEA uses and what you're trying to access. Here's how to fix it:
- Open your Run/Debug Configurations (click the dropdown next to the run button, then select "Edit Configurations...")
- Pick your Tomcat server config, then switch to the Deployment tab
- Look at the Application context field for your deployed artifact. If it's set to something like
/your-project-name, you'd need to visithttp://localhost:8080/your-project-nameinstead of the root. Since you're hittinglocalhost:8080/, make sure this field is set to/ - Save the changes, restart Tomcat, and try accessing the URL again
2. Verify Your Deployed Artifact Type & Content
IDEA might be deploying an incomplete or incorrect artifact. Let's confirm:
- Open Project Structure (use Ctrl+Alt+Shift+S on Windows/Linux, Cmd+; on Mac)
- Go to Artifacts
- Ensure you're deploying a Web Application: Exploded artifact (this is the best option for debugging, as it's unzipped and easy to modify)
- Check that the artifact includes:
- All files from
src/main/webapp(static resources, WEB-INF folder, etc.) - The
classesdirectory (your compiled Java files) from your module's output
- All files from
- If any content is missing, click the "+" button to add the missing directories or modules
3. Fix Web Facet Configuration
The Web Facet tells IDEA where your web resources live—if this is wrong, deployment will fail silently:
- Still in Project Structure, go to Facets > Web
- Confirm the Web Resource Directories points to
src/main/webapp(Maven's standard web root directory) - Check that Deployment Descriptor is set to
src/main/webapp/WEB-INF/web.xml - Make sure the Context root here matches the Application context you set in the Tomcat deployment config (usually
/for root access)
4. Clean & Rebuild to Fix Sync Issues
Sometimes IDEA fails to sync the latest build to Tomcat's temporary directory. Let's reset this:
- Stop the Tomcat server in IDEA
- Go to Build > Clean Project to wipe old build files
- Then run Build > Rebuild Project to generate fresh files
- (Optional) Delete Tomcat's unpacked deployment directory (you can find its path in the Deployment tab of your Tomcat config, under "Unpacked directory")
- Restart Tomcat and try accessing the URL again
5. Check web.xml for Welcome Page Configuration
If none of the above works, double-check your web.xml—Tomcat might not know which page to serve at the root:
Add or verify the welcome-file list in your web.xml:
<welcome-file-list> <welcome-file>index.jsp</welcome-file> <welcome-file>index.html</welcome-file> </welcome-file-list>
Also ensure your servlet mappings are correct if you're using a custom controller to serve the root path.
内容的提问来源于stack exchange,提问作者Wang Jian

