Study that first line of error message. On the left, notice jakarta.
. On the right, notice javax.
.
Java EE ➠ Jakarta EE
A few years ago, Oracle transferred ownership and control of the Java Enterprise Edition (Java EE) specifications and technologies to the Eclipse Foundation. Thus, Java EE became Jakarta EE. The trademark Java is owned by Oracle Corp., and so that term must be removed from new artifacts produced by the Eclipse Foundation.
As part of that handover transition, the package naming changed from javax.*
to jakarta.*
.
You are using a version of Apache Tomcat, v 10, built for the jakarta.*
package naming. The Tomcat community is developing another version on parallel, same features, same performance, different package naming.
So you have two choices:
- Continue using Tomcat 10, while changing your
import
statements to use jakarta.*
package naming.
- Switch to using Tomcat 9, while keeping your
import
statements to javax.*
.
If your project is new and greenfield, or small and simple, then I recommend the first. That way you are future-ready. There is no downside other than remembering to adjust the package naming whenever copy-pasting code or reading older articles.
Another benefit is that the latest versions of the Jakarta EE implementations are built to support Java 11 (required) and support Java 17 (optional, but generally done). For this, choose Tomcat 10.1.x rather than 10.0.x. See Tomcat documentation, Which Tomcat?.
If your project is existing, and large, then you may want to put off the chore of transitioning. In this case, stick with Tomcat 9. I suspect you will eventually want to transition, but you may defer for a few years.
By the way, the equivalent competitor to Tomcat, Eclipse Jetty, has chosen the same approach. Jetty development is being done in two parallel versions with same features, same performance, different package naming.
Now is a bit of a confusing time during this Oracle-to-Eclipse transition. To help you get oriented, you can watch any of many video presentations on YouTube, etc. including some published by the Jakarta EE project itself.