You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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 visit http://localhost:8080/your-project-name instead of the root. Since you're hitting localhost: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 classes directory (your compiled Java files) from your module's output
  • 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:

  1. Stop the Tomcat server in IDEA
  2. Go to Build > Clean Project to wipe old build files
  3. Then run Build > Rebuild Project to generate fresh files
  4. (Optional) Delete Tomcat's unpacked deployment directory (you can find its path in the Deployment tab of your Tomcat config, under "Unpacked directory")
  5. 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 08:01:40