java.lang.NoClassDefFoundError: javax/servlet/ServletRequestListener

I’ve followed the installation guide for XWiki using Tomcat. I’m using Tomcat 10 (10.0.4) with java 15.0.2 2021-01-19. However, every time Tomcat tries to deploy the XWiki application, it fails with the following error:

Apr 03, 2021 2:34:05 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Error configuring application listener of class [org.xwiki.container.servlet.XWikiServletContextListener]
java.lang.NoClassDefFoundError: javax/servlet/ServletContextListener
        at java.base/java.lang.ClassLoader.defineClass1(Native Method)
        at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
        at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:151)
        at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(Unknown Source)
        at org.apache.catalina.loader.WebappClassLoaderBase.findClass(Unknown Source)
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(Unknown Source)
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(Unknown Source)
        at org.apache.catalina.core.DefaultInstanceManager.loadClass(Unknown Source)
        at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(Unknown Source)
        at org.apache.catalina.core.DefaultInstanceManager.newInstance(Unknown Source)
        at org.apache.catalina.core.StandardContext.listenerStart(Unknown Source)
        at org.apache.catalina.core.StandardContext.startInternal(Unknown Source)
        at org.apache.catalina.util.LifecycleBase.start(Unknown Source)
        at org.apache.catalina.core.ContainerBase.addChildInternal(Unknown Source)
        at org.apache.catalina.core.ContainerBase.addChild(Unknown Source)
        at org.apache.catalina.core.StandardHost.addChild(Unknown Source)
        at org.apache.catalina.startup.HostConfig.deployWAR(Unknown Source)
        at org.apache.catalina.startup.HostConfig$DeployWar.run(Unknown Source)
        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at org.apache.tomcat.util.threads.InlineExecutorService.execute(Unknown Source)
        at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:118)
        at org.apache.catalina.startup.HostConfig.deployWARs(Unknown Source)
        at org.apache.catalina.startup.HostConfig.deployApps(Unknown Source)
        at org.apache.catalina.startup.HostConfig.start(Unknown Source)
        at org.apache.catalina.startup.HostConfig.lifecycleEvent(Unknown Source)
        at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(Unknown Source)
        at org.apache.catalina.util.LifecycleBase.setStateInternal(Unknown Source)
        at org.apache.catalina.util.LifecycleBase.setState(Unknown Source)
        at org.apache.catalina.core.ContainerBase.startInternal(Unknown Source)
        at org.apache.catalina.core.StandardHost.startInternal(Unknown Source)
        at org.apache.catalina.util.LifecycleBase.start(Unknown Source)
        at org.apache.catalina.core.ContainerBase$StartChild.call(Unknown Source)
        at org.apache.catalina.core.ContainerBase$StartChild.call(Unknown Source)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at org.apache.tomcat.util.threads.InlineExecutorService.execute(Unknown Source)
        at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140)
        at org.apache.catalina.core.ContainerBase.startInternal(Unknown Source)
        at org.apache.catalina.core.StandardEngine.startInternal(Unknown Source)
        at org.apache.catalina.util.LifecycleBase.start(Unknown Source)
        at org.apache.catalina.core.StandardService.startInternal(Unknown Source)
        at org.apache.catalina.util.LifecycleBase.start(Unknown Source)
        at org.apache.catalina.core.StandardServer.startInternal(Unknown Source)
        at org.apache.catalina.util.LifecycleBase.start(Unknown Source)
        at org.apache.catalina.startup.Catalina.start(Unknown Source)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:564)
        at org.apache.catalina.startup.Bootstrap.start(Unknown Source)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:564)
        at org.apache.commons.daemon.support.DaemonLoader.start(DaemonLoader.java:241)
Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletContextListener
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(Unknown Source)
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(Unknown Source)
        ... 55 more

Apr 03, 2021 2:34:05 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Error configuring application listener of class [org.xwiki.container.servlet.SetThreadNameServletRequestListener]
java.lang.NoClassDefFoundError: javax/servlet/ServletRequestListener
        at java.base/java.lang.ClassLoader.defineClass1(Native Method)
        at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
        at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:151)
        at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(Unknown Source)
        at org.apache.catalina.loader.WebappClassLoaderBase.findClass(Unknown Source)
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(Unknown Source)
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(Unknown Source)
        at org.apache.catalina.core.DefaultInstanceManager.loadClass(Unknown Source)
        at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(Unknown Source)
        at org.apache.catalina.core.DefaultInstanceManager.newInstance(Unknown Source)
        at org.apache.catalina.core.StandardContext.listenerStart(Unknown Source)
        at org.apache.catalina.core.StandardContext.startInternal(Unknown Source)
        at org.apache.catalina.util.LifecycleBase.start(Unknown Source)
        at org.apache.catalina.core.ContainerBase.addChildInternal(Unknown Source)
        at org.apache.catalina.core.ContainerBase.addChild(Unknown Source)
        at org.apache.catalina.core.StandardHost.addChild(Unknown Source)
        at org.apache.catalina.startup.HostConfig.deployWAR(Unknown Source)
        at org.apache.catalina.startup.HostConfig$DeployWar.run(Unknown Source)
        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at org.apache.tomcat.util.threads.InlineExecutorService.execute(Unknown Source)
        at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:118)
        at org.apache.catalina.startup.HostConfig.deployWARs(Unknown Source)
        at org.apache.catalina.startup.HostConfig.deployApps(Unknown Source)
        at org.apache.catalina.startup.HostConfig.start(Unknown Source)
        at org.apache.catalina.startup.HostConfig.lifecycleEvent(Unknown Source)
        at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(Unknown Source)
        at org.apache.catalina.util.LifecycleBase.setStateInternal(Unknown Source)
        at org.apache.catalina.util.LifecycleBase.setState(Unknown Source)
        at org.apache.catalina.core.ContainerBase.startInternal(Unknown Source)
        at org.apache.catalina.core.StandardHost.startInternal(Unknown Source)
        at org.apache.catalina.util.LifecycleBase.start(Unknown Source)
        at org.apache.catalina.core.ContainerBase$StartChild.call(Unknown Source)
        at org.apache.catalina.core.ContainerBase$StartChild.call(Unknown Source)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at org.apache.tomcat.util.threads.InlineExecutorService.execute(Unknown Source)
        at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140)
        at org.apache.catalina.core.ContainerBase.startInternal(Unknown Source)
        at org.apache.catalina.core.StandardEngine.startInternal(Unknown Source)
        at org.apache.catalina.util.LifecycleBase.start(Unknown Source)
        at org.apache.catalina.core.StandardService.startInternal(Unknown Source)
        at org.apache.catalina.util.LifecycleBase.start(Unknown Source)
        at org.apache.catalina.core.StandardServer.startInternal(Unknown Source)
        at org.apache.catalina.util.LifecycleBase.start(Unknown Source)
        at org.apache.catalina.startup.Catalina.start(Unknown Source)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:564)
        at org.apache.catalina.startup.Bootstrap.start(Unknown Source)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:564)
        at org.apache.commons.daemon.support.DaemonLoader.start(DaemonLoader.java:241)
Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletRequestListener
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(Unknown Source)
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(Unknown Source)
        ... 55 more

Apr 03, 2021 2:34:05 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Skipped installing application listeners due to previous error(s)
Apr 03, 2021 2:34:05 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: One or more listeners failed to start. Full details will be found in the appropriate container log file
Apr 03, 2021 2:34:05 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [] startup failed due to previous errors

I’m not sure what I’m doing wrong. I’m using Arch Linux, AMD 64, postgresql as my database server, kernel 5.11.10.
Edit: I also added the security policy to /etc/tomcat10/catalina.policy and altered it to fit my environment.

You’re using Tomcat 10.x which is not supported (and nor is Java 15 btw). See https://www.xwiki.org/xwiki/bin/view/Documentation/AdminGuide/Installation/#HHardwareandSoftwarerequirements

Thanks. I’ve switched to using the docker container. However, the xwiki container’s Java implementation is crashing with this weird error:

xwiki  | 05-Apr-2021 01:11:47.697 INFO [main] org.apache.coyote.http11.AbstractHttp11Protocol.configureUpgradeProtocol The ["https-openssl-nio2-8443"] connector has been configured to support negotiation to [h2] via ALPN
xwiki  | 05-Apr-2021 01:11:47.698 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["https-openssl-nio2-8443"]
xwiki  | #
xwiki  | # A fatal error has been detected by the Java Runtime Environment:
xwiki  | #
xwiki  | #  SIGSEGV (0xb) at pc=0x000069e0f6582e71, pid=1, tid=59
xwiki  | #
xwiki  | # JRE version: OpenJDK Runtime Environment AdoptOpenJDK (11.0.10+9) (build 11.0.10+9)
xwiki  | # Java VM: OpenJDK 64-Bit Server VM AdoptOpenJDK (11.0.10+9, mixed mode, tiered, compressed oops, g1 gc, linux-amd64)
xwiki  | # Problematic frame:
xwiki  | # V  [libjvm.so+0x5a9e71]  AccessInternal::PostRuntimeDispatch<G1BarrierSet::AccessBarrier<1097844ul, G1BarrierSet>, (AccessInternal::BarrierType)2, 1097844ul>::oop_access_barrier(void*)+0x1
xwiki  | #
xwiki  | # Core dump will be written. Default location: Core dumps may be processed with "/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %h" (or dumping to /usr/local/tomcat/core.1)
xwiki  | #
xwiki  | # An error report file with more information is saved as:
xwiki  | # /usr/local/tomcat/hs_err_pid1.log
xwiki  | #
xwiki  | # If you would like to submit a bug report, please visit:
xwiki  | #   https://github.com/AdoptOpenJDK/openjdk-support/issues
xwiki  | #
xwiki  |
xwiki  | [error occurred during error reporting (), id 0xb, SIGSEGV (0xb) at pc=0x000069e0f75ab941]
xwiki  |
xwiki exited with code 127

This happened after I modified the tomcat connector to look like this:

    <Connector port="8443" protocol="org.apache.coyote.http11.Http11Nio2Protocol"
               maxThreads="150" SSLEnabled="true" secure="true" scheme="https">
        <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
        <SSLHostConfig>
            <Certificate certificateKeyFile="tomcat.key"
                         certificateFile="tomcat.pem"
                         type="RSA" />
        </SSLHostConfig>
    </Connector>

My full XML file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<Server port="8005" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
  <Listener className="org.apache.catalina.security.SecurityListener" />
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
  <GlobalNamingResources>
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>
  <Service name="Catalina">
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11Nio2Protocol"
               maxThreads="150" SSLEnabled="true" secure="true" scheme="https">
        <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
        <SSLHostConfig>
            <Certificate certificateKeyFile="tomcat.key"
                         certificateFile="tomcat.pem"
                         type="RSA" />
        </SSLHostConfig>
    </Connector>
    <Engine name="Catalina" defaultHost="localhost">
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>
      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />
      </Host>
    </Engine>
  </Service>
</Server>

I’ve also modified the docker-compose.yml file to use host as the network mode, but I don’t see how that could actually break things like this. The key and certificate files do exist.