Tomcat 10.x throws java.lang.NoClassDefFoundError on javax.servlet.* [duplicate]

According to your logs,

C:\Users\Ing.Girbson BIJOU\Documents\NetBeansProjects\apache-tomcat-10.0.4-windows-x64\apache-tomcat-10.0.4\conf\Catalina\localhost\VirtualStore.xml

you’re thus using Tomcat 10.x which is based off Servlet API version 5.0 which in turn is part of Jakarta EE version 9.

However, this exception is unexpected:

java.lang.NoClassDefFoundError: javax/servlet/ServletRequestListener

Basically, the deployed web application is looking for javax.servlet.*, but it should actually be looking for jakarta.servlet.*. Namely, the javax.* package has been renamed to jakarta.* package since Jakarta EE version 9. This thus means that the deployed web application is actually not compatible with Jakarta EE version 9. The deployed web application is most likely developed for an older JEE version where the javax.* package is still used.

So, summarized, the targeted JEE versions don’t match up and it’s causing trouble for you. You have 2 options:

  1. Downgrade Tomcat to version 9.x. This is the latest available version which still uses the javax.* package. This is however not the recommended option in long term as the javax.* package is clearly a dead end for JEE.

  2. Or, upgrade the deployed web application to target Jakarta EE 9+ instead. I.e. adjust the project’s dependencies (e.g. pom.xml) to reference JEE 9+ based versions instead, and then perform a project-wide Find & Replace of javax.* to jakarta.* (of course except for javax.naming.* and javax.xml.* and probably a few others, but the Java compiler will quickly point out them for you).

See also:

  • Apache Tomcat – Versions
  • How to properly configure Jakarta EE libraries in Maven pom.xml for Tomcat? (this answer contains complete examples of proper pom.xml declarations for Tomcat 10+, Tomcat 9-, JEE 9+ and JEE 8-).

Leave a Comment

tech