javax vs jakarta namespace in a Java web application
Match servlet imports, dependency versions and the finished WAR to the target container, while keeping Java SE types such as javax.sql.DataSource in their original packages.
- EE 8 Servlet package
- javax.servlet
- EE 9 Servlet package
- jakarta.servlet
- EE 9 database connection factory
- javax.sql.DataSource
Decision guide
- Jakarta EE 8
- Keep the javax.servlet build when the deployed container implements Servlet 4.0 and required filters or other libraries still expose those types.
- Jakarta EE 9
- Build the jakarta.servlet variant for a Servlet 5.0 or newer target, selecting the API level and library versions that the target actually implements.
- Deciding factor
- The first component crossing a servlet type boundary determines whether a request can complete. Check the compiled WAR and its libraries together on each supported target.
Comparison matrix
| Decision factor | Jakarta EE 8 | Jakarta EE 9 |
|---|---|---|
| Servlet API package | javax.servlet | jakarta.servlet |
| API artifact on the specification page | 4.0.3 | 5.0.0 |
| JDBC data source type | javax.sql.DataSource | javax.sql.DataSource |
Which package does the deployed container provide?
Choose the servlet package from the target container’s specification level, then compile every component that crosses that boundary against the corresponding API.
Java EE 8 and Jakarta EE 8 applications use javax.servlet for servlet interfaces. Jakarta EE 9 moved these APIs to jakarta.servlet. A filter compiled against the old interface and a container expecting the new interface refer to different Java types. Matching method names do not make the types interchangeable. Adding an import to the application servlet fixes only the code compiled from that source. A packaged listener or filter may still carry the previous name in its compiled method signatures.
Take a request that passes through a third-party filter before reaching your servlet. On an EE 8 target, both components must agree on the servlet types that travel between them. On an EE 9 target, both need the corresponding Jakarta types. List that filter as a deployment dependency even if it never appears in your controllers’ import statements. Its class may be discovered during application startup or only when a particular configuration or route activates it. Use the integration path that causes it to run.
Which javax imports still belong in the application?
Identify the specification or JDK module that owns each type before changing its prefix.
A servlet can use jakarta.servlet.http.HttpServlet and obtain database connections from javax.sql.DataSource in the same source file. The latter interface belongs to the Java SE java.sql module. Jakarta EE 9 itself uses that type when describing a resource-manager connection factory. A replacement rule that invents jakarta.sql.DataSource would damage working database code. Likewise, identifying a reference in a string literal tells you where to investigate, not which package should replace it.
Sort the inventory by owner. Put servlet interfaces, filters and listeners in one group. Put JDBC interfaces supplied by the JDK in another. For names exposed by a vendor library, inspect the documentation or source for the exact library release. Keep an explicit decision for each group in the migration change so that reviewers can see why an old prefix remains. Testing a servlet that retrieves a data source, executes a disposable query and returns the value checks both sides of this boundary in a single request.
Why can a Jakarta artifact still contain javax classes?
Read the artifact version as well as its group and artifact names.
The Jakarta Servlet 4.0 specification lists jakarta.servlet:jakarta.servlet-api:4.0.3. The Servlet 5.0 specification lists the same group and artifact with version 5.0.0. The earlier specification still has the old servlet package. A search for dependencies whose group begins with “jakarta” cannot prove a web application uses the new package. Read the selected version in the resolved dependency tree. Then inspect the actual API classes expected by any library that accepts a servlet request or returns a servlet response.
For an application packaged as a WAR for an external container, identify which APIs the container supplies at runtime. Configure the build dependency scope accordingly and inspect the finished archive for an accidental second copy. A test runner can see classes provided by its own class path that the deployed application cannot see. For an embedded server, record the server dependencies brought in by the application framework. Changing an API dependency while leaving the embedded server at its old level can make the compiler happy and still leave a type mismatch at startup.
What should the packaged WAR be checked for?
Review the archive produced by the release build, including class files, nested library JARs and deployment metadata.
Start by listing WEB-INF/classes, WEB-INF/lib and any deployment descriptors. Search the application source for imports, fully qualified class names in configuration, service-provider declarations and names loaded reflectively. Use the dependency inventory to locate JARs that register filters or listeners. Source searches do not inspect bytecode in a library shipped by another team. Have the library owner identify a compatible artifact or build a candidate from the appropriate source revision. Record exactly which artifact reached the WAR.
For an application that uses web.xml, compare its declared schema and version with the deployment descriptor documentation for the selected servlet level. Check class references inside it individually. A resource reference may correctly name javax.sql.DataSource while a filter registration needs a Jakarta-compatible class. Applications that discover components through annotations or service metadata also need a startup test with those components present. Keep a manifest of archive entries or checksums from each build so an unexpected packaged dependency can be traced to the change that introduced it.
Which server and Java combination should run the trial?
Use the runtime branch planned for service and verify the servlet specification and minimum Java version independently.
Tomcat 9 implements Servlet 4.0. The 10.0 branch introduced Servlet 5.0 and the namespace change. Apache now lists 10.0 as unsupported. Tomcat 10.1 implements Servlet 6.0 and lists Java 11 or later. These entries answer different questions. A guide to the historical 9-to-10 namespace change describes the package transition, while the current version matrix tells you which specification a particular operating branch implements. Check the selected patch and JDK distribution against the support agreement your team relies on.
Suppose a new service depends on a Servlet 6.0 feature and uses jakarta.servlet throughout. The package name alone cannot establish it will run on a Servlet 5.0 container. Compile against the target level, deploy the shipping artifact on that level and exercise the feature. Give any JDK change its own acceptance criterion. A class-file version error is evidence about the compiler and virtual machine combination. A failure to resolve a servlet type points to a different part of the compatibility record.
Prove the replacement and keep a deployable previous version
Keep the previous container configuration and compatible WAR together until the new deployment passes a representative request and restart.
On the target, inspect application startup, invoke a route passing through the third-party filter, obtain a real connection from the test data source and exercise an error response. If the service uses JSPs or other views compiled on demand, visit a representative view after a cold start. A successful health endpoint may never load those classes. Record the deployed artifact digest, server version, JDK and the exact failing class name when an operation fails. Retest the operation after changing a dependency instead of relying on a clean build alone.
If the team uses a bytecode migration tool, keep the original artifact and identify the transformed one by a separate digest. Apache documents conversion options for the package change. Conversion still needs the same checks for library behavior, configuration and features implemented by the target. For rollback, retain a matching pair of archive and runtime and account for any database or session-format changes independently. Reverting a server image cannot make an earlier application understand records written in a new format.
Frequently asked questions
Does upgrading the JDK rename servlet imports?
Changing the JDK updates the Java platform available to the application. The servlet package is determined by the enterprise API and container selected for deployment.
Can we use one source repository for both servlet namespaces?
Yes, if the build produces and tests an appropriate artifact for each supported target. Keep shared business code free of servlet-specific types where practical and make the target-specific dependencies explicit.
Methodology and sources
The comparison follows the Jakarta EE 8 and 9 specifications, published Servlet artifacts, Java SE documentation and Apache’s container compatibility matrix. The deployment checks cover an example WAR with a filter and a JDBC resource.
- Jakarta EE 8 platform and API specifications
- Jakarta EE 9 platform, compatibility and resource references
- Jakarta Servlet 4.0 specification and artifact coordinates
- Jakarta Servlet 5.0 specification and artifact coordinates
- Apache Tomcat migration guide for the namespace transition
- Apache Tomcat servlet and Java version matrix
- Java SE 21 API for javax.sql.DataSource