• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Tomcat and dlls

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I have a webapp that uses dlls and I have two questions about this.

1. Is there anyway to put the dlls in the war and have Tomcat find them. BTW there are 8 dlls, and one uses the others. For the moment I have the dlls in the bin of Tomcat (or on the path), and that works OK.

2. If a wabapp fails then usually you can restart it in Tomcat without restarting Tomcat. BUT when I restart my webapp, it tries to reload the dlls and Tomcat complains that they are already there. How can I unload the dlls without restarting Tomcat?

Maybe these two questions are related, if I manage to put the dlls in the war, Tomcat would unload them with the app? Or am I just being hopeful.

For the time being I am using Tomcat 5.5 but could change to Tomcat 6 if these questions whould be easier to answer. And I certainly will if I am the lucky winner of the SUPER new book "Professional Apache Tomcat 6". Oooh pick me, pick me!

Thanks in advance for any help

Nicole

 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nichole,

It looks, from the release notes, that this will be no different in version 6 than in prior versions.

I don't think it matters (to Tomcat, and Java) where you put the actual DLLs but the Java classes that load them should be under Tomcat/shared.

From:
http://download.nextag.com/apache/tomcat/tomcat-6/v6.0.14/RELEASE-NOTES


=======================
JNI Based Applications:
=======================
Applications that require native libraries must ensure that the libraries have
been loaded prior to use. Typically, this is done with a call like:

static {
System.loadLibrary("path-to-library-file");
}

in some class. However, the application must also ensure that the library is
not loaded more than once. If the above code were placed in a class inside
the web application (i.e. under /WEB-INF/classes or /WEB-INF/lib), and the
application were reloaded, the loadLibrary() call would be attempted a second
time.

To avoid this problem, place classes that load native libraries outside of the
web application, and ensure that the loadLibrary() call is executed only once
during the lifetime of a particular JVM.

 
Nicole Lacoste
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ben,

I am working on it. First of all I noticed that in an normal app (not Tomcat) I can call System.loadLibrary() serveral times in a row with the same dll with no exceptions or complaints. I haven't yet tested under Tomcat. Also you said (or quoted)

To avoid this problem, place classes that load native libraries outside of the web application, and ensure that the loadLibrary() call is executed only once during the lifetime of a particular JVM.



How?

Nicole
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not a JNI expert but I can tell you what I'm doing.

We use a third party middleware library that consists of one DLL and one Jar file. If we have more than one copy of our app running and we put the jar file in the WEB-INF/lib directory of each app, the first app to use it locks all the others out.
To fix this we've placed the jar file under tomcat/shared/lib (we're using Tomcat 5.5 right now).
With the jar file in that location all the applications can access the middleware without a problem.

I'm assuming there is a static reference of some sort to the objects that make the JNI connections that only gets loaded when the first request for it comes in (like in the sample from the release notes above). Since the classloaders for the tomcat/shared/lib and the tomcat/common/lib directories are outside of our application, restarting the app, doesn't affect them.

Does this help?
[ October 03, 2007: Message edited by: Ben Souther ]
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Follow this link to unload dll:

http://www.codethesis.com/blog/unload-java-jni-dll

I tried it with my web application running on Tomcat, and it works!

Briefly, I call System.loadLibrary from the class which is loaded by my custom class loader using reflection. This class is then removed by garbage collector.
 
reply
    Bookmark Topic Watch Topic
  • New Topic