tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael LeValle <tom...@levalle.net>
Subject Re: REPOST (+more comments) - Classloading problems with JNI
Date Thu, 08 Aug 2002 16:06:10 GMT
Hi Shimon,

I've done no work with JNI, but have read a little on it.

My understanding is that when making calls from native
to java, the native code often instantiates a new JVM. If
your are doing this then I would suspect that this is your problem.

Your newly instantied JVM would not have access to the classes
loaded in the Tomcat JVM instance. Even if you included these in
your CLASSPATH (as you mentioned with Jetty) then you'd be
accessing java classes in a JVM seperate from the one that Tomcat
is using (which is not what I think you want to do).

It seems that you'd somehow need to, first make a java->C++ call
to your native code to give it a handle to the Tomcat JVM instance,
and from there use this handle in your native code to access or invoke
the java classes/objects that you so desire.

Michael LeValle


Shimon Crown wrote:

>I asked this question a couple of days ago but only got 1 reply which
>unfortunately didn't solve the problem. Hence the repost.
>
>Tomcat 4.0.  J2SDK1.4 (Windows NT4).
>
>I have a couple of jars that use JNI. Originally I put these jars into the
>applications web-inf directory. Presumably these classes were only loaded
>once as everything went okay as far as calling from java to C++ code goes.
>The native code performs a callback into classes defined in these jars and
>has to create java classes defined by me. Unfortunately the native dll is
>unable to locate these classes and I fail in the native line
>
>     jclass variantClass = env->FindClass("MYCLASS");
>
> The same thing happens when I put the JNI jars in %CATALINA_HOME%/lib which
>I believe is the correct place for them.
>
>I have tried other directories including  %CATALINA_HOME%\server\lib. When
>using these other directories it seems that the JNI classes are loaded twice
>as Tomcat just hangs and fails to initialize the servlets that I have setup
>to load at startup.
>
> I tried the same thing with jetty web server and found that JNI is unable
>to find classes in the web-inf/lib directory. However if I included these
>JNI containing jars as part of the classpath that I gave when running the
>Jetty server then it could find them.
>
>As an interim solution I have found that I can split the problem causing
>jars into Java->C++ calling and other classes. The other classes which are
>called from C++ can safely be put in a common CATALINA directory where the
>classloader used by JNI will find them.
>
>Can anyone provide me with a definitive explanation of the classloading
>behaviour I am seeing. Is there a way to solve this problem without breaking
>up the jars ?
>
>Shimon Crown
>
>
>
>
>--
>To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
>For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>
>
>
>
>




--
To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>


Mime
View raw message