java-11apache-axisclassnotfoundexceptiontomcat9axiom

OMLinkedListMetaFactory ClassCastException in a Tomcat Project on OpenSuse Server but not Locally


I'm working with two projects: one is a webservice and the other contains the business logic. The webservice project has a dependency on the business logic project.

To run the project, I'm using Tomcat 9.0.65 and Java 11, with Maven for dependency management.

When I run the project in my local environment, everything works correctly. But when I generate the .war file and deploy it to a server running OpenSuse 12, I encounter the following error:

javax.servlet.ServletException: javax.servlet.ServletException: java.lang.ClassCastException: class org.apache.axiom.om.impl.llom.factory.OMLinkedListMetaFactory cannot be cast to class org.apache.axiom.om.OMMetaFactorySPI (org.apache.axiom.om.impl.llom.factory.OMLinkedListMetaFactory and org.apache.axiom.om.OMMetaFactorySPI are in unnamed module of loader org.apache.catalina.loader.ParallelWebappClassLoader @5b40ceb)
    org.apache.axis2.transport.http.AxisServlet.init(AxisServlet.java:462)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
    org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:687)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:360)
    org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:399)
    org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
    org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:890)
    org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1789)
    org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
    org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
    org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    java.base/java.lang.Thread.run(Thread.java:834)
causa raíz

javax.servlet.ServletException: java.lang.ClassCastException: class org.apache.axiom.om.impl.llom.factory.OMLinkedListMetaFactory cannot be cast to class org.apache.axiom.om.OMMetaFactorySPI (org.apache.axiom.om.impl.llom.factory.OMLinkedListMetaFactory and org.apache.axiom.om.OMMetaFactorySPI are in unnamed module of loader org.apache.catalina.loader.ParallelWebappClassLoader @5b40ceb)
    org.apache.axis2.transport.http.AxisServlet.initConfigContext(AxisServlet.java:591)
    org.apache.axis2.transport.http.AxisServlet.init(AxisServlet.java:454)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
    org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:687)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:360)
    org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:399)
    org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
    org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:890)
    org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1789)
    org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
    org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
    org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    java.base/java.lang.Thread.run(Thread.java:834)
causa raíz

java.lang.ClassCastException: class org.apache.axiom.om.impl.llom.factory.OMLinkedListMetaFactory cannot be cast to class org.apache.axiom.om.OMMetaFactorySPI (org.apache.axiom.om.impl.llom.factory.OMLinkedListMetaFactory and org.apache.axiom.om.OMMetaFactorySPI are in unnamed module of loader org.apache.catalina.loader.ParallelWebappClassLoader @5b40ceb)
    org.apache.axiom.om.OMXMLBuilderFactory.createOMBuilder(OMXMLBuilderFactory.java:165)
    org.apache.axiom.om.OMXMLBuilderFactory.createOMBuilder(OMXMLBuilderFactory.java:145)
    org.apache.axiom.om.OMXMLBuilderFactory.createOMBuilder(OMXMLBuilderFactory.java:116)
    org.apache.axis2.util.XMLUtils.toOM(XMLUtils.java:590)
    org.apache.axis2.util.XMLUtils.toOM(XMLUtils.java:575)
    org.apache.axis2.deployment.DescriptionBuilder.buildOM(DescriptionBuilder.java:97)
    org.apache.axis2.deployment.AxisConfigBuilder.populateConfig(AxisConfigBuilder.java:90)
    org.apache.axis2.deployment.DeploymentEngine.populateAxisConfiguration(DeploymentEngine.java:857)
    org.apache.axis2.deployment.WarBasedAxisConfigurator.<init>(WarBasedAxisConfigurator.java:156)
    org.apache.axis2.transport.http.AxisServlet.initConfigContext(AxisServlet.java:584)
    org.apache.axis2.transport.http.AxisServlet.init(AxisServlet.java:454)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
    org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:687)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:360)
    org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:399)
    org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
    org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:890)
    org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1789)
    org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
    org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
    org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    java.base/java.lang.Thread.run(Thread.java:834)

The error seems to be related to the Apache Axiom class. When I check the libraries of the project deployed on the server, I see that the Axiom libraries are duplicated. This is because the webservice is using Axiom version 1.2.13, and the business logic project is using version 1.4.0. When I manually delete the 1.4.0 library, the project works on the server.

I've tried to exclude this library in my local environment, but doing so throws many errors. I also tried using the same version of Axiom (both 1.2.13 and 1.4.0) in both projects, but it doesn't work in my local environment due to incompatibility issues with the apache-axis version.

Could this be a problem with how Tomcat handles dependencies in Linux? Is there something else I might be overlooking? Any guidance would be greatly appreciated.

Thanks in advance.


Solution

  • I was finally able to solve my problem, which was being affected by three key factors.

    1. Axis2 and Axiom Versions: I had to revert back to older versions of axis2 and axiom to avoid conflicts. The versions that finally worked for me are as follows:

      <axiom.version>1.2.13</axiom.version>
      <axis2.version>1.6.2</axis2.version>
      
    2. Library Load Order: The order in which libraries were loading in my project was also affecting things. Be sure to check and adjust this as needed in your own project.

    3. JDK 11 Incompatibilities: I also ran into an issue where javax.xml.stream was accessible by more than one module. To fix this, I had to exclude the following libraries from my dependencies:

      <dependency>
          <groupId>org.apache.ws.commons.axiom</groupId>
          <artifactId>axiom-api</artifactId>
          <version>${axiom.version}</version>
          <exclusions>
              <exclusion>
                  <groupId>org.apache.james</groupId>
                  <artifactId>apache-mime4j-core</artifactId>
              </exclusion>
              <exclusion>
                  <groupId>org.apache.geronimo.specs</groupId>
                  <artifactId>
                      geronimo-activation_1.1_spec
                  </artifactId>
              </exclusion>
              <exclusion>
                  <groupId>org.apache.geronimo.specs</groupId>
                  <artifactId>geronimo-stax-api_1.0_spec</artifactId>
              </exclusion>
          </exclusions>
      </dependency>
      
      <dependency>
          <groupId>org.apache.ws.commons.axiom</groupId>
          <artifactId>axiom-impl</artifactId>
          <version>${axiom.version}</version>
          <exclusions>
              <exclusion>
                  <groupId>org.apache.geronimo.specs</groupId>
                  <artifactId>
                      geronimo-activation_1.1_spec
                  </artifactId>
              </exclusion>
              <exclusion>
                  <groupId>org.apache.geronimo.specs</groupId>
                  <artifactId>geronimo-stax-api_1.0_spec</artifactId>
              </exclusion>
          </exclusions>
      </dependency>
      
      <dependency>
          <groupId>org.apache.ws.commons.axiom</groupId>
          <artifactId>axiom-dom</artifactId>
          <version>${axiom.version}</version>
          <exclusions>
              <exclusion>
                  <groupId>org.apache.geronimo.specs</groupId>
                  <artifactId>
                      geronimo-activation_1.1_spec
                  </artifactId>
              </exclusion>
          </exclusions>
      </dependency>
      
      <dependency>
          <groupId>org.apache.axis2</groupId>
          <artifactId>axis2-adb</artifactId>
          <version>${axis2.version}</version>
          <exclusions>
              <exclusion>
                  <groupId>org.apache.geronimo.specs</groupId>
                  <artifactId>
                      geronimo-activation_1.1_spec
                  </artifactId>
              </exclusion>
          </exclusions>
      </dependency>
      

    I hope this information can help someone else facing similar issues. Thanks to everyone for the help provided.