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
?