Tomcat10 Error: java.lang.NoClassDefFoundError: javax/servlet/ServletContextListener

It turns out that there is a problem with the matching between the versions of Servlet, JSP and Spring. As we all know, in 2018, Java EE was renamed Jakarta EE. This resulted in the package names of some JAR packages being changed in later versions. The impact of this on this project is that Spring itself does not contain Servlet and JSP JAR packages, but it relies on these JAR packages. If the project deployed in the Tomcat server uses Spring, this part of the JAR package will be provided by the Tomcat server. The problem is that the JAR package prefix expected by Spring 5.2.9.RELEASE is javax, while the JAR package prefix provided by Tomcat 10.0.0 is jakarta. Therefore, Spring reported an error that there is no JAR package for Servlet or JSP.

(The URL for viewing the Servlet and other versions corresponding to each version of Tomcat is:

Since Tomcat is closely related to the JAR packages of Servlet and JSP, it cannot be solved by replacing the JAR packages of Servlet and JSP in the folder lib under Tomcat. Moreover, this cannot be solved by adding the correct Servlet and JSP dependencies in Maven. In fact, if the pure Java code part of the project does not use the JAR packages of Servlet and JSP, in fact, the Servlet and JSP dependencies added in Maven are here. Can be deleted. (In a more professional way, in Maven-based Web applications, the scope of dependency on Servlet and JSP is provided.)

Fortunately, the JAR package prefix used by Tomcat 9.0.41 is javax. Therefore, you only need to install another Tomcat 9.0.41 here (the existing Tomcat does not need to be uninstalled, because the installation path of different versions of Tomcat can be different, but the existing Tomcat server needs to be shut down during installation to avoid occupying the same A port number).

Similar Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *