首页 > 解决方案 > EAR 中的 java.lang.NoClassDefFoundError

问题描述

我创建了一个 EAR,其中有一个 WAR 并部署到 wildfly 服务器。该项目需要 sapjco3.jar 才能运行。我将 jar 放在服务器上并在 EAR 中创建一个 XML 来使用它。

<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
    <!-- Make sub deployments isolated by default, so they cannot see each others classes without a Class-Path entry -->
    <ear-subdeployments-isolated>false</ear-subdeployments-isolated>
    <!-- This corresponds to the top level deployment. For a war this is the war's module, for an ear -->
    <!-- This is the top level ear module, which contains all the classes in the EAR's lib folder     -->
    <deployment>
        <exclusions>
            <module name="org.apache.log4j" />
        </exclusions>
        <!-- This allows you to define additional dependencies, it is the same as using the Dependencies: manifest attribute -->
        <dependencies>
            <module name="deployment.nana-app.ear" export="true" />
            <module name="deployment.sapjco3.jar" export="true" />
        </dependencies>
        <!-- These add additional classes to the module. In this case it is the same as including the jar in the EAR's lib directory -->
        <resources> 
        </resources>
    </deployment>
</jboss-deployment-structure>

部署成功,但是当我使用它时发生以下错误。

    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.RuntimeException: java.lang.NoClassDefFoundError: Could not initialize class com.sap.conn.jco.JCo
    ... 206 more
Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.sap.conn.jco.JCo
    at com.sap.conn.jco.JCoDestinationManager.getDestination(JCoDestinationManager.java:77)
    at com.SAPcall.SAPcallBean.ContractCreate(SAPcallBean.java:586)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

jar 位置是正确的,因为我有另一个 WAR 使用它并且那个可以工作。那么我的项目有什么问题?我需要在战争中添加配置吗?谢谢。

标签: javawildflyjco

解决方案


推荐阅读