3 Replies Latest reply on Apr 24, 2003 12:25 AM by jbossalex

    JNI and JBOSS???

    alexjboss

      Hi:

      Can anyone provide me any information regarding how to load a native library at startup for the JBOSS Container. I am trying to load a native library written in C++ which I can access via JNI from the command line. However, when I access this library via an EJB which talks to my JNI wrappers I get the following error:

      java.lang.UnsatisfiedLinkError: new_TestDate__SWIG_2

      I realize the EJB spec states that accessing a JNI/native code is prohibited, but some newsgroups recommended a work around where the native library is loaded via the Container instead of the EJB. By the way, I am using a stateful session bean.

      Any ideas recommendations (excluding CORBA) would greatly be appreciated!!

      JBOSS is an awesome product!

      Many Thanks:

      Alex

        • 1. Re: JNI and JBOSS???

          Write an MBean that does the

          System.loadLibrary("whatever");

          You are correct, you shouldn't be doing this
          by spec.

          Regards,
          Adrian

          • 2. Re: JNI and JBOSS???
            haraldgliebe

            Actually JARDeployer resp. its super class SubDeployerSupport does that already.
            SubDeployerSupport calls System.load(..) for every dynamic library found in a jar file that is deployed. However, since the call to System.load is in SubDeployerSupport (which is not loaded by UCL) the native library is associated with the wrong classloader and thus unusable for the code in the deployed jar file.

            What is the use case of this deployment of native libraries in SubDeployerSupport? Has it worked before?

            • 3. Re: JNI and JBOSS???
              jbossalex

              Hi :

              I loaded the native dll library using the MBEAN approach, but I am still getting unsatisfied link errors.
              I called System.loadLibrary() in a static initializer in my MBEAN:

              static
              {
              try
              {
              //loads the project_api.dll
              System.out.println("....................STARTING LOADING THE DLL");
              System.loadLibrary("project_api");
              System.out.println("....................FINISHED LOADING THE DLL");
              }
              catch(UnsatisfiedLinkError unsatisfiedlinkerror)
              {
              String lErrorMsg = "Native project_api code library failed to load.\n";
              System.out.println(lErrorMsg + unsatisfiedlinkerror.getMessage());
              System.exit(1);
              }


              Can anyone refer me to an example of using an MBEAN to load a Native Library or provide me with any ideas? By the way, I implemented a Standard MBEAN.


              I then called my MBEAN from my Stateful Session EJB and once again I received an UnsatisfiedLink Exception.

              Many Thanks:
              Alex