Quick revision
The short answer
Tomcat 10.1 implements jakarta.servlet, so a WAR still built on javax.ws.rs and Jersey 2 is simply invisible to it. We check that every dependency moved to Jersey 3.1 or later with jakarta.ws.rs imports everywhere, that jersey-container-servlet and its initializer are on the classpath and web.xml names jakarta-era classes, that no javax annotations remain (they compile but are ignored), and that scanning and the application path match the servlet mapping, then confirm registration from Jersey's startup log or an OpenAPI endpoint.
What to remember
In this answer, we saw why a javax-based WAR returns 404 on Tomcat 10.1 without errors: the runtime looks for jakarta.* classes and ignores everything else. We checked the dependency tree for Jersey 2 and javax artifacts, the servlet initializer and a jakarta-namespace web.xml, leftover javax imports that compile but are ignored, and the packages and paths that make up the final URL, and then confirmed registration through Jersey's startup log, WADL or an OpenAPI endpoint. A build rule that forbids javax imports keeps the fix in place.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Tomcat 10.1 implements jakarta.servlet, so a WAR still built on javax.ws.rs and Jersey 2 is simply invisible to it. We check that every dependency moved to Jersey 3.1 or later with jakarta.ws.rs imports everywhere, that jersey-container-servlet and its initializer are on the classpath and web.xml names jakarta-era classes, that no javax annotations remain (they compile but are ignored), and that scanning and the application path match the servlet mapping, then confirm registration from Jersey's startup log or an OpenAPI endpoint.
Why this question is asked
The javax to jakarta move broke more deployments than any change in Java web history, because it changed package names without changing behaviour, and old and new classes can coexist on the classpath without errors. A WAR that returns 404 for every endpoint with no stack trace is the classic symptom. Interviewers ask this to see whether we debug methodically from the runtime upward instead of changing things at random. In this answer, we will recap what changed and why it causes silence rather than errors, then walk through the checks in order: the container and Jersey versions, the servlet wiring, leftover javax annotations, scanning and paths, and finally how to confirm what was registered.
1A Quick Recap of the javax to jakarta Move
When Java EE moved to the Eclipse Foundation and became Jakarta EE, the javax.* package names could not be used for new versions. Jakarta EE 9 renamed them to jakarta.*: javax.servlet became jakarta.servlet and javax.ws.rs became jakarta.ws.rs. Tomcat 10 and later implement jakarta.servlet; Tomcat 9 was the last javax version. Jersey followed the same split: Jersey 2.x uses javax.ws.rs, Jersey 3.0 and 3.1 use jakarta.ws.rs (3.1 for Jakarta EE 10, the right choice for Tomcat 10.1), and Jersey 4 targets Jakarta EE 11.
The important point is that a class annotated with javax.ws.rs.Path and a class annotated with jakarta.ws.rs.Path are, to the runtime, completely unrelated. A Jakarta-era Jersey looks for jakarta.ws.rs.Path. It finds nothing, logs nothing alarming, and every request returns 404.
2Check 1: Is Anything Still javax-Based?
We start at the bottom, with the dependency tree. The first question is whether Tomcat is even loading a Jakarta-era Jersey.
Jersey 2's ServletContainerInitializer implements javax.servlet.ServletContainerInitializer, which Tomcat 10.1 never calls, so no Jersey servlet is ever started. Also look for transitive javax artifacts from older libraries, for example a Swagger or Jackson JAX-RS provider still on its javax version, because those providers will also be silently ignored. If an injection module such as jersey-hk2 is missing, Jersey 3 does fail loudly at startup, which is a useful contrast: a loud error points at wiring, silence points at packages.
3Check 2: The Servlet Wiring and web.xml
Next we check how Jersey is started. With jersey-container-servlet on the classpath, its initializer picks up an @ApplicationPath class automatically. If the project uses web.xml instead, the servlet class name and the deployment descriptor version must both be Jakarta-era.
The class name ServletContainer is the same in Jersey 2 and 3, which is why this can look correct while the jar behind it is the old one. Note that jersey-container-servlet-core does not include the initializer, so with that artifact the web.xml declaration is required.
4Check 3: Mixed Annotations That Compile but Do Nothing
The sneakiest case: dependencies are correct, but some source files still import javax.ws.rs. This compiles fine whenever a javax API jar is still on the compile classpath, for example through a transitive dependency.
The fix is to migrate every import, which tools do reliably: OpenRewrite's Jakarta migration recipes for source code, or the Apache Tomcat migration tool for Jakarta EE for a built WAR. Then we exclude the javax API artifacts entirely, and ideally add an enforcer rule or ArchUnit test that fails the build if any javax.ws.rs or javax.servlet import returns.
5Check 4: Scanning and Paths
With wiring fixed, a remaining 404 is often a path mismatch. The real URL is context root, then servlet mapping or @ApplicationPath, then @Path. If web.xml maps the servlet to /api/* and the Application also says @ApplicationPath("/api"), the descriptor wins for that servlet, and an app that mixes both can end up at an unexpected place. And ResourceConfig.packages must name the package that actually holds the resources, including subpackages if we pass true for recursive scanning, while an overridden Application.getClasses must list every resource.
Finally we confirm. Jersey can log the registered resources at startup when tracing or monitoring is enabled, an OpenAPI endpoint (for example from Swagger Core's jakarta artifacts) lists every operation it found, and Jersey's WADL endpoint, application.wadl under the application path if WADL is enabled, does the same. If the list is empty, the problem is still registration; if the list is right and requests still 404, compare the URL with the paths in the list.
- Any javax.ws.rs or Jersey 2 jar in the tree?YesMove to Jersey 3.1 and jakarta APIsNoNext check
- Is jersey-container-servlet or a jakarta web.xml in place?YesNext checkNoAdd the initializer or servlet
- Any javax imports left in source?YesMigrate with OpenRewrite, ban in CINoNext check
- Do packages and paths match the URL?YesConfirm with startup log or OpenAPINoFix packages, mapping or @ApplicationPath
4 steps in order. Play them, or step through them one at a time.
6Follow-up questions
Why does Tomcat 10.1 not log an error for the old Jersey jar?
Because from Tomcat's point of view nothing is wrong. It looks for implementations of jakarta.servlet.ServletContainerInitializer and finds none, so it starts the web application with no Jersey servlet. The old classes are just unused bytes on the classpath, and requests to /api fall through to the default servlet, which returns 404.
Could we stay on Tomcat 9 instead?
As a short-term step, yes, because Tomcat 9 still supports javax and gets updates for now. But it locks us out of the Jakarta ecosystem, and newer versions of Spring, Hibernate and most libraries are jakarta-only, so the migration only gets more expensive. I would use Tomcat 9 only to separate the container upgrade from the code migration, and then finish the move.
Does Jackson need changes too?
Yes. The JSON provider must be the jakarta variant, for example jersey-media-json-jackson from Jersey 3, or Jackson's jakarta-rs providers. A javax-based provider is ignored just like old resources, and the symptom changes from 404 to 500 or 415 errors about a missing message body writer.
7Conclusion
In this answer, we saw why a javax-based WAR returns 404 on Tomcat 10.1 without errors: the runtime looks for jakarta.* classes and ignores everything else. We checked the dependency tree for Jersey 2 and javax artifacts, the servlet initializer and a jakarta-namespace web.xml, leftover javax imports that compile but are ignored, and the packages and paths that make up the final URL, and then confirmed registration through Jersey's startup log, WADL or an OpenAPI endpoint. A build rule that forbids javax imports keeps the fix in place.
Open with
My first suspicion is the javax to jakarta split, because 404 everywhere with no stack trace is its classic symptom. Tomcat 10.1 implements jakarta.servlet, and Jersey 2 is javax-based, so Tomcat never calls Jersey 2's initializer and no resources are registered.
Then, if they want more
So I check the dependency tree first: we need Jersey 3.1 or later, with jakarta.ws.rs-api, jersey-hk2 for injection, and the jakarta versions of any JSON or OpenAPI providers, and no javax artifacts arriving transitively. Second, the wiring: either jersey-container-servlet with its ServletContainerInitializer picking up the @ApplicationPath class, or a web.xml using the jakarta namespace and pointing at ServletContainer.
Third, leftover javax.ws.rs imports in the source. They compile if an old API jar is on the classpath, but the new runtime treats those classes as unannotated, so I migrate them with OpenRewrite or the Tomcat migration tool and add a build rule that bans javax imports.
Fourth, scanning and paths: ResourceConfig.packages must name the right package, and the URL is context root plus the servlet mapping or application path plus the resource path. Finally I confirm with Jersey's startup log, WADL or an OpenAPI endpoint which resources were actually registered.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Jakarta EE 10, Jakarta EE 11, Jakarta EE 9
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Jakarta EE specifications
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "After upgrading a WAR from javax.ws.rs (Jersey 2) to Jakarta REST on Tomcat 10.1, all...": https://scrivio-interview-library.netlify.app/java/jax-rs/801e3b7b46/