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

huangapple go评论55阅读模式
英文:

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

问题

我正在处理两个项目:一个是WebService,另一个包含业务逻辑。WebService项目依赖于业务逻辑项目。

为了运行该项目,我使用Tomcat 9.0.65和Java 11,使用Maven进行依赖管理。

当我在本地环境中运行项目时,一切正常。但是当我生成.war文件并部署到运行OpenSuse 12的服务器时,我遇到了以下错误:

错误似乎与Apache Axiom类相关。当我检查部署在服务器上的项目的库时,我发现Axiom库是重复的。这是因为WebService使用Axiom版本1.2.13,而业务逻辑项目使用版本1.4.0。当我手动删除1.4.0库时,项目在服务器上可以正常工作。

我尝试在本地环境中排除此库,但这样做会引发许多错误。我还尝试在两个项目中使用相同版本的Axiom(1.2.13和1.4.0),但由于与apache-axis版本不兼容的问题,无法在我的本地环境中工作。

这可能与Tomcat在Linux中处理依赖项有关吗?还有其他我可能忽视的问题吗?任何指导将不胜感激。

提前致谢。

英文:

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.

答案1

得分: 0

我终于成功解决了我的问题,这个问题受到了三个关键因素的影响。

  1. Axis2 和 Axiom 版本: 我不得不回退到较旧的 axis2 和 axiom 版本,以避免冲突。最终对我有效的版本如下:

    <axiom.version>1.2.13</axiom.version>
    <axis2.version>1.6.2</axis2.version>
    
  2. 库加载顺序: 在我的项目中,库加载的顺序也会影响事情。请确保根据需要检查并调整您自己项目中的加载顺序。

  3. JDK 11 不兼容性: 我还遇到了一个问题,即 javax.xml.stream 可以由多个模块访问。为了解决这个问题,我不得不从我的依赖项中排除以下库:

    <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 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.

huangapple
  • 本文由 发表于 2023年7月17日 16:59:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/76702885.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定