tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Benzel <ben...@entelos.com>
Subject RE: Classloader, JNI and "already loaded in another classloader"
Date Fri, 01 Jun 2001 18:13:58 GMT
I'll give it try.  Thanks.

-----Original Message-----
From: Bo Xu [mailto:bo@cybershop.ca]
Sent: Friday, June 01, 2001 10:56 AM
To: tomcat-user@jakarta.apache.org
Subject: Re: Classloader, JNI and "already loaded in another
classloader"


> [...]
> >I have a webapp running under Tomcat 3.2.1 that needs to make JNI calls
in
> >order to access data and methods in legacy C++ code.  A servlet is loaded
> >on startup of the webapp that, as part if its init method, causes a data
set
> >specific to that webapp instance to be loaded into the C++ data
structures.
> >This Java code for this servlet contains the following:
> >
> >    static
> >    {
> >        try {
> >            System.loadLibrary("JCoreImpl");
> >            System.out.println("JCoreImpl loaded");
> >            m_bLibraryLoaded = true;
> >        } catch (UnsatisfiedLinkError e) {
> >            m_bLibraryLoaded = false;
> >            System.out.println("JCoreImpl NOT loaded " + e);
> >        }
> >    }
> >
> >Things work fine if there is only one webapp (let's call it
"webapps/aaa").
> >If I have a second webapp ("webapps/bbb") that is identical to
webapps/aaa
> >except for the data set used in the C++ data structures, then webapps/aaa
> >starts up just fine, but when webapps/bbb is started I get an error
stating
> >that:
> >
> >JCoreImpl NOT loaded java.lang.UnsatisfiedLinkError: Native Library
> >E:\WebStation\binDebug\JCoreImpl.dll already loaded in another
classloader
> >
> >I need to have a separate instance of the native library for each of my
> >webapps as each instance needs to contain data that is unique to that
> >particular webapp.  I have searched through the mail archives and read
> >emails by Craig McLanahan explaining the classloader hierarchy.  But I
have
> >not been able to find anything specific to loading a unique instance of a
> >native library for each webapp.
> >
> >Any ideas?  Thanks,
> >
> >Mark

Hi :-) is the following possible?

- don't put "System.loadLibrary("JCoreImpl")" in Servlet class,
   but put it in a utility class which is loaded by a classloader who is
   "upper" than the classloader of "aaa" or "bbb".  for example, put this
    utility class and the native code Both in TOMCAT_HOME/lib

- then in the "init" method of those Servlet classes in webapp "aaa"
   or "bbb", first load that utility class, then/so load the native code.


Bo
June.01, 2001




Mime
View raw message