0

I am trying to build a webapplication project using Netbeans 12.4 and Tomcat 10.0.13. And I am surprised to see my project compile well but the context listener is never invoked. Instead I see messages like

java.lang.NoClassDefFoundError: javax/servlet/ServletContextListener
Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletContextListener

in the logs. My war does not bundle servet API and solutions as with ClassNotFoundException with ServletContextlistener seem to not work, so I went another path and tried to find the ServletContextListener class in the Tomcat installation. And found it in ${CATALINA_HOME}/lib/servlet-api.jar. So far so good.

But when I inspected the jar further, the fully qualified class name is jakarta.servlet.ServletContextListener. Alarmed, I searched on and found https://tomcat.apache.org/tomcat-10.0-doc/servletapi/index.html?jakarta/servlet/ServletContextListener.html

This does not look like a glitch, does it? But then, how am I expected to write a Java webapplication? Should I compile versus javax.servlet.XXX or jakarta.servlet.XXX ?

Queeg
  • 7,748
  • 1
  • 16
  • 42
  • 1
    Tomcat 10 is JakartaEE **not** JavaEE. – M. Deinum Dec 07 '21 at 07:56
  • Thank you for the quick response. Switching my project and dependencies from JavaEE to JakartaEE actually helped. It effectively means to compile versus jakarta.servlet. I was not aware about that huge breach. – Queeg Dec 07 '21 at 09:34

0 Answers0