You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Dirk Griesbach <dg...@eurocom-depora.de> on 2003/09/11 15:58:25 UTC

TC and JNI...

Hi there and good afternoon world,

I have a question regarding JNI and Tomcat (4.1.27):

A servlet loads a DLL via 

    static { 
    System.loadLibrary("SharedLib"); 
    }

This statement placed directly in my servlet works fine.

But when another servlet is about to use some functions included in the same .DLL 
you have to use a different classloader (than the one invoked out of /WEB-INF/classes) to avoid multiple loads of this DLL.

So I wrote a primitive class that simply does this static load of the kind

package abcd;

public class LoadTheLib {
    public void LoadTheLib()
    {;};
        
    static {
        System.loadLibrary("SharedLib");
        System.out.println("SharedLib loaded");
    }
    public String printVersion()
    {
     return ("Loader 0.1");
    }
}

put the class (as jar) in '/common/lib', leave the DLL where it is 
(it will be found via PATH) restart and ...'unsatisfied link error'.

When I call the constructor in my servlet via
....
LoadTheLib loader = new LoadTheLib (); 
System.out.println(loader.printVersion());
....
( which is nonsense in this context, but only to test)

both messages appear ('SharedLib loaded' and 'Loader 0.1');
but still: 'unsatisfied link error'.

Any idea of what's wrong ? 
How to make TC load this sharedlib on startup so that other servlets can share it ?

best regards

dirk