javazktomcat10

Why do I get java.lang.ClassNotFoundException: org.zkoss.zk.ui.http.HttpSessionListener when I try to run a deployed zk war?


I am trying to run a deployed .war made with the zk framework and Java, in a Debian server with tomcat 10 but it doesn't work. When I checked the log in the file /opt/tomcat/logd/localhost.2021-xx-xx.log, an error message appeared as follows:

java.lang.ClassNotFoundException: org.zkoss.zk.ui.http.HttpSessionListener 

Then, I made some research on the internet and I found a possible solution on this link https://forum.zkoss.org/question/97112/javalangclassnotfoundexception-orgzkosszkuihttphttpsessionlistener/ and I did what is suggested. However, the error continues to appear. It seems that there is a conflict between the zk framework and the server.


Solution

  • I see two potential issues that could cause this.

    First: Tomcat 10 implements Jakarta servlet (instead of java servlet). When building your application, make sure that you are using the proper ZK version. The last ZK release has two versions:

    See the configuration guide here.

    Caveat on that, if you are running the Java EE version of ZK in tomcat 10, I'd expect you to get:

    [org.zkoss.zk.ui.http.HttpSessionListener]
        java.lang.NoClassDefFoundError: javax/servlet/ServletRequestAttributeListener
    

    which is located in the same place as your current issue, but is not quite the same :D

    Second: If you are resolving your dependencies through a dependency management tool such as maven or graddle, it is possible that you are resolving the wrong dependencies.

    I'd recommend doublechecking the resolved depencies to make sure that every single one of the ZK jars are resolved in the same version.

    You may have a ZK version coming from your main declaration, and a different one coming from a plugin (such as Keikai, ZK spreadsheet, or ZK charts)

    From maven for example, running the dependency tree command is a good way to know what is resolved.