Hendrik,
I came across this issue with JNI libs some years ago, and also comes
up in the context of most app servers, which use a multitude of
classloaders to enable hot code reloading and such. The general
solution is to move your JNI lib into your boot classpath; in my
experience with Tomcat and Weblogic years ago, doing this caused the
boot classloader to link the JNI lib, making it available from all
child classloaders. See #3 here:
http://www.bostic.com/docs/bdb_current/ref/java/faq.html
Creating a new classloader is really important to enable proper GC'ing
of any dynamically-generated classes later on, as others have said.
This also only happens when one loads code, which will generally only
happen at or near app startup outside of a development environment, so
performance isn't really a concern IMO.
- Chas