Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Deployed servlet based web application at context path [/VirtualStore], but context failed to start with below log.

19-Mar-2021 11:46:35.075 INFO [main] org.apache.catalina.startup.HostConfig.deployDescriptor Deployment of deployment descriptor [C:\Users\Ing.Girbson BIJOU\Documents\NetBeansProjects\apache-tomcat-10.0.4-windows-x64\apache-tomcat-10.0.4\conf\Catalina\localhost\VS.xml] has finished in [448] ms
19-Mar-2021 11:46:35.079 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\Users\Ing.Girbson BIJOU\Documents\NetBeansProjects\apache-tomcat-10.0.4-windows-x64\apache-tomcat-10.0.4\webapps\docs]
19-Mar-2021 11:46:35.291 WARNING [main] org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [143] milliseconds.
19-Mar-2021 11:46:35.306 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\Users\Ing.Girbson BIJOU\Documents\NetBeansProjects\apache-tomcat-10.0.4-windows-x64\apache-tomcat-10.0.4\webapps\docs] has finished in [228] ms
19-Mar-2021 11:46:35.307 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\Users\Ing.Girbson BIJOU\Documents\NetBeansProjects\apache-tomcat-10.0.4-windows-x64\apache-tomcat-10.0.4\webapps\examples]
19-Mar-2021 11:46:35.613 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\Users\Ing.Girbson BIJOU\Documents\NetBeansProjects\apache-tomcat-10.0.4-windows-x64\apache-tomcat-10.0.4\webapps\examples] has finished in [307] ms
19-Mar-2021 11:46:35.613 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\Users\Ing.Girbson BIJOU\Documents\NetBeansProjects\apache-tomcat-10.0.4-windows-x64\apache-tomcat-10.0.4\webapps\host-manager]
19-Mar-2021 11:46:35.646 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\Users\Ing.Girbson BIJOU\Documents\NetBeansProjects\apache-tomcat-10.0.4-windows-x64\apache-tomcat-10.0.4\webapps\host-manager] has finished in [32] ms
19-Mar-2021 11:46:35.646 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\Users\Ing.Girbson BIJOU\Documents\NetBeansProjects\apache-tomcat-10.0.4-windows-x64\apache-tomcat-10.0.4\webapps\manager]
19-Mar-2021 11:46:35.676 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\Users\Ing.Girbson BIJOU\Documents\NetBeansProjects\apache-tomcat-10.0.4-windows-x64\apache-tomcat-10.0.4\webapps\manager] has finished in [29] ms
19-Mar-2021 11:46:35.676 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\Users\Ing.Girbson BIJOU\Documents\NetBeansProjects\apache-tomcat-10.0.4-windows-x64\apache-tomcat-10.0.4\webapps\ROOT]
19-Mar-2021 11:46:35.703 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\Users\Ing.Girbson BIJOU\Documents\NetBeansProjects\apache-tomcat-10.0.4-windows-x64\apache-tomcat-10.0.4\webapps\ROOT] has finished in [27] ms
19-Mar-2021 11:46:35.708 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8085"]
19-Mar-2021 11:46:35.726 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [1894] milliseconds
19-Mar-2021 11:46:36.546 INFO [http-nio-8085-exec-9] org.apache.catalina.startup.HostConfig.undeploy Undeploying context [/VirtualStore]
19-Mar-2021 11:46:36.562 INFO [http-nio-8085-exec-4] org.apache.catalina.startup.HostConfig.deployDescriptor Deploying deployment descriptor [C:\Users\Ing.Girbson BIJOU\Documents\NetBeansProjects\apache-tomcat-10.0.4-windows-x64\apache-tomcat-10.0.4\conf\Catalina\localhost\VirtualStore.xml]
19-Mar-2021 11:46:36.563 WARNING [http-nio-8085-exec-4] org.apache.catalina.startup.HostConfig.deployDescriptor The path attribute with value [/VirtualStore] in deployment descriptor [C:\Users\Ing.Girbson BIJOU\Documents\NetBeansProjects\apache-tomcat-10.0.4-windows-x64\apache-tomcat-10.0.4\conf\Catalina\localhost\VirtualStore.xml] has been ignored
19-Mar-2021 11:46:36.934 SEVERE [http-nio-8085-exec-4] org.apache.catalina.startup.HostConfig.deployDescriptor Error deploying deployment descriptor [C:\Users\Ing.Girbson BIJOU\Documents\NetBeansProjects\apache-tomcat-10.0.4-windows-x64\apache-tomcat-10.0.4\conf\Catalina\localhost\VirtualStore.xml]
    java.lang.IllegalStateException: Error starting child
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:720)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:690)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:743)
        at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:692)
        at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:540)
        at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1777)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:288)
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
        at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
        at org.apache.catalina.manager.ManagerServlet.check(ManagerServlet.java:1570)
        at org.apache.catalina.manager.ManagerServlet.deploy(ManagerServlet.java:1022)
        at org.apache.catalina.manager.ManagerServlet.doGet(ManagerServlet.java:357)
        at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:663)
        at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:770)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:223)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:185)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158)
        at org.apache.catalina.filters.HttpHeaderSecurityFilter.doFilter(HttpHeaderSecurityFilter.java:126)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:185)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:668)
        at org.apache.catalina.valves.RequestFilterValve.process(RequestFilterValve.java:378)
        at org.apache.catalina.valves.RemoteAddrValve.invoke(RemoteAddrValve.java:56)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
        at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:353)
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374)
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:870)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1696)
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Thread.java:748)
    Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/VirtualStore]]
        at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:440)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:198)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:717)
        ... 44 more
    Caused by: java.lang.NoClassDefFoundError: javax/servlet/ServletRequestListener
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2470)
        at org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:866)
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1370)
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1224)
        at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:540)
        at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:521)
        at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:151)
        at org.apache.catalina.core.ApplicationContext.addListener(ApplicationContext.java:1086)
        at org.apache.catalina.core.ApplicationContextFacade.addListener(ApplicationContextFacade.java:664)
        at org.apache.jasper.servlet.JasperInitializer.onStartup(JasperInitializer.java:92)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5115)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
        ... 45 more
    Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletRequestListener
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1401)
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1224)
        ... 60 more

How is this caused and how can I solve it?

like image 370
Girbson BIJOU Avatar asked Mar 19 '21 16:03

Girbson BIJOU


People also ask

How to fix error java lang NoClassDefFoundError?

You can fix NoClassDefFoundError error by checking following: Check the exception stack trace to know exactly which class throw the error and which is the class not found by java.

What causes NoClassDefFoundError?

The NoClassDefFoundError is a runtime error in Java that occurs if the Java Virtual Machine (JVM) or a ClassLoader instance attempts to load the definition of a class that could not be found. The class definition exists at compile-time but is not available at runtime.

Where is javax servlet package?

It contains, among others, the files /usr/share/java/servlet-api-2.5. jar and /usr/share/java/jsp-api-2.1. jar , which are the servlet and JSP libraries you need.


1 Answers

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.

java.lang.NoClassDefFoundError: javax/servlet/ServletRequestListener

This is unexpected. 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.

  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 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
  • Tomcat 9 casting servlets to javax.servlet.Servlet instead of jakarta.servlet.http.HttpServlet (this answer contains complete examples of proper pom.xml declarations for Tomcat 10+, Tomcat 9-, JEE 9+ and JEE 8-).
like image 51
BalusC Avatar answered Oct 04 '22 03:10

BalusC