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

NetBeans 8.2中Maven Web应用Tomcat无法运行但GlassFish正常求助

Hey there! Let’s troubleshoot why your RESTful app is throwing an HTTP 404 on Tomcat but works perfectly on GlassFish. Since it’s a default Maven project, here are the most common culprits to check step by step:

1. Double-Check the Context Path

Tomcat uses your WAR file’s name as the default context path unless you explicitly configure it. For example, if your WAR is named my-rest-service.war, your base request URL should be http://localhost:8080/my-rest-service/—not just http://localhost:8080/. GlassFish might have used a different default (like your project’s raw name without the .war suffix), so make sure your test URLs match Tomcat’s expected path.

2. Validate Servlet Mappings (Annotations or web.xml)

If you’re using traditional web.xml instead of Jakarta EE annotations, ensure your REST servlet is mapped correctly. For JAX-RS apps, this usually looks like:

<servlet>
    <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <init-param>
        <param-name>jersey.config.server.provider.packages</param-name>
        <param-value>com.yourcompany.rest</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Jersey REST Service</servlet-name>
    <url-pattern>/api/*</url-pattern>
</servlet-mapping>

If you’re using annotations like @ApplicationPath, confirm it’s set properly (e.g., @ApplicationPath("/api")) and your resource classes have @Path annotations that align with the URLs you’re testing.

3. Confirm Tomcat Version Compatibility

Tomcat versions have strict Jakarta EE/JAX-RS support rules:

  • Tomcat 9 uses Java EE 8 (JAX-RS 2.1, with javax.* packages)
  • Tomcat 10+ uses Jakarta EE 9+ (JAX-RS 3.0, with jakarta.* packages)
    If your Maven dependencies are using javax.ws.rs but you’re running Tomcat 10+, you’ll hit classpath issues. Check your pom.xml—for Tomcat 10+, switch to Jakarta EE artifacts (e.g., jakarta.ws.rs:jakarta.ws.rs-api:3.1.0 instead of javax.ws.rs:javax.ws.rs-api:2.1.1).
4. Dig Into Tomcat’s Logs

Don’t overlook Tomcat’s log files! Check logs/catalina.out and localhost.log in your Tomcat installation directory. Look for class-not-found errors, deployment failures, or servlet initialization exceptions. These logs will often spell out exactly why your app isn’t starting (like missing JAX-RS implementation jars such as Jersey or RESTEasy).

5. Ensure Your Maven Build Produces a Valid WAR

Verify your pom.xml has <packaging>war</packaging> set. Run mvn clean package and inspect the generated WAR in the target folder—make sure all necessary dependencies are included. GlassFish includes some Jakarta EE libraries out of the box, so if you marked dependencies as <scope>provided</scope> for GlassFish, those jars won’t be in your WAR and Tomcat (a servlet-only container) won’t have them either.

6. Check Tomcat’s Deployment Status

Head to Tomcat’s Manager app (http://localhost:8080/manager/html), log in, and see if your app is listed as "Running". If it’s not started, try launching it manually—sometimes Tomcat fails to deploy apps silently due to configuration glitches, and the manager will show you the error when you attempt to start it.

One key difference between GlassFish and Tomcat: GlassFish is a full Jakarta EE server that includes JAX-RS out of the box. Tomcat is just a servlet container, so you need to include a JAX-RS implementation (like Jersey) in your WAR or install it as a Tomcat library. Double-check that those jars are present in your WEB-INF/lib folder!

内容的提问来源于stack exchange,提问作者Rieske

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 03:30:22