geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chris Brooking" <cjbrook...@googlemail.com>
Subject Re: JNI from a geronimo EJB
Date Thu, 18 May 2006 11:31:20 GMT
Hi,
I have now solved this problem. The key is that the DLL cannot be loaded at
class initialization time. At serverv startup these classes are loaded with
a different class loader, and if the DLL is loaded this makes it unloadable
when called by the EJB class. To do this,  in the native method class,
instead of having a statement like

_static {
    System.loadLibrary("GeronimoJniTest");
}

I had to have an initialization method, like

private static final synchronized void init() throws JniCallerException {

        if (!initialized) {
            try {
                System.loadLibrary("GeronimoJniTest");
                initialized = true;
            } catch (Throwable e) {
                throw new JniCallerException("init exception: ", e);
            }
        }
    }


Then in each JNI method call I had a call to the init method.

public native long nativeAttach(long[] sessid, long wsno, String profile)
            throws JniCallerException;

public long attach(long[] sessid, long wsno, String profile)
            throws JniCallerException {
        init();
        try {
            return nativeAttach(sessid, wsno, profile);
        } catch (JniCallerException e) {
            throw e;
        }
        catch (Throwable t) {
            throw new JniCallerException("attach error :" +
            t.getClass().getName() + " - " + t.getMessage(), t);
        }

    }

This seems to work when the JNI class is in a jar file in the .ear, and this
is added to the ejb .jar manifest class path, or if it is deployed as a
common library and referenced by a dependency entry in the
geronimo-application.xml as follows:

<dependency>
  <uri>lib/JNI/1.0/jar</uri>
</dependency>

I have to say that the stack traces returned to the client application when
the failures occurred were not as helpful as they could have been, as they
were traces of the transaction rollback rather than the underlying cause.

I hope that this is useful to anyone else trying to use JNI from geronimo
EJBs as I did not find any references to this problem on the web.

   Chris Brooking



On 5/17/06, Chris Brooking <cjbrooking@googlemail.com> wrote:
>
> I need to access a windows library from an EJB.....
>
Is it possible to use JNI from an EJB on geronimo? If so where should I
> place the library or how should I deploy it?
>
>
>
>

Mime
View raw message