javaeclipsejbossjco

SAP JBOSS issues with jar


I am trying to connect my J2EE application with SAP software using ABAP function calls. When I run it as a single class in Eclipse with hot coded values, it works fine. When I try to run it in JBoss server, where I am getting some values from my front end and passing it to my Java class which is the same class I referred before, it shows this following exception

java.lang.NoClassDefFoundError: com/sap/conn/jco/JCoException
  at java.lang.Class.getDeclaredMethods0(Native Method)
  at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
  at java.lang.Class.privateGetPublicMethods(Unknown Source)
  at java.lang.Class.getMethods(Unknown Source)
  at org.jboss.aop.ClassContainer.createMethodMap(ClassContainer.java:182)

  
    09:35:42,326 INFO  [EARDeployer] Started J2EE application:
                    file:/F:/jboss/jboss-4.2.3.GA/server/default/deploy/MPCS.ear
    09:35:42,326 ERROR [URLDeploymentScanner] Incomplete Deployment listing:

    --- MBeans waiting for other MBeans ---
    ObjectName: jboss.j2ee:service=EJB3,module=MPCS.jar
     State: FAILED
     Reason: java.lang.NoClassDefFoundError: com/sap/conn/jco/JCoException

    --- MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM ---
    ObjectName: jboss.j2ee:service=EJB3,module=MPCS.jar
    State: FAILED
    Reason: java.lang.NoClassDefFoundError: com/sap/conn/jco/JCoException

I have my sapjco3.jar in F:/jar where I also have ejb3-persistence.jar, jboss-ejb3x.jar, etc. and they are properly recognized. I have added the jar in build path also. But nothing helps.


Solution

  • I had a similar problem with the NoClassDefFoundError in JBoss EAP 6.1 when using classes from sapjco3.jar in an EJB (annotated with @Singleton and @Startup). Besides that I also received an error saying that the native library was already loaded in another classloader when republishing to EAP or restarting the deployed module.

    My solution to both problems was to include sapjco3.jar as a global JBoss module.

    Step 1

    I created the following structure inside EAPS's \modules folder:

    com
    --> sap
        --> conn
            --> jco
                --> main
                    --> module.xml
                    --> sapjco3.jar
    

    The contents of module.xml:

    <?xml version="1.0" encoding="UTF-8"?>
       <module xmlns="urn:jboss:module:1.0" name="com.sap.conn.jco">
       <resources>
          <resource-root path="sapjco3.jar"/>
       </resources>
    </module>
    

    Step 2

    Adding the module as a global module in standalone.xml:

    <subsystem xmlns="urn:jboss:domain:ee:1.1">
       ... 
       <global-modules>
           <module name="com.sap.conn.jco" />
       </global-modules>
       ...
    </subsystem>
    

    Step 3

    Create or edit file jboss-deployment-structure.xml inside EJB projects META-INF to contain the module. My file looks like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <jboss-deployment-structure>
       <deployment>
          <dependencies>
             <module name="com.sap.conn.jco" export="TRUE" />
          </dependencies>
       </deployment>
    </jboss-deployment-structure>
    

    Step 4

    Configure Maven dependency as scope provided, so that we can work with sapjco3.jar inside the workspace but not have it inside the deployment.

    <dependency>
       <groupId>com.sap.conn.jco</groupId>
       <artifactId>sapjco3</artifactId>
       <version>3.0.10</version>
       <scope>provided</scope>
    </dependency>
    

    That is what I recall so far to make it work, maybe this is helpful for you or anybody else.