https://bz.apache.org/bugzilla/show_bug.cgi?id=62830
--- Comment #16 from Christopher Schultz <ch...@christopherschultz.net> --- (In reply to Igal Sapir from comment #13) > (In reply to Christopher Schultz from comment #12) > > Sorry... I must be missing something, here. > > > > System.loadLibrary isn't ClassLoader-specific... once the library has been > > loaded, it can't be loaded again at all. > > > > The code here is all fine, and using a Listener makes a lot of sense. But > > the documentation suggests that somehow loading a shared lib in a different > > ClassLoader changes something when it doesn't. Instead, you are asking > > Tomcat to load it *once* (at the server level) and then not again. > > > > If you try to use this <Listener> at the <Context> level, it will fail when > > re-deploying the <Context>, just like if the application had used > > It's counter-intuitive, I know. Here's what I tested right now, tell me know > if covers the scenario you described above: > > In conf/server.xml, I added the following snippet to the Server, Service, > and in conf/Catalina/localhost/ROOT.xml, > conf/Catalina/localhost/context_1.xml, conf/Catalina/localhost/context_2.xml > to the Context element: > > > <Listener className="org.apache.catalina.core.JniLifecycleListener" > > libraryName="opencv_java343" /> > > Below are the relevant log entries: > > > 22-Oct-2018 18:45:04.739 INFO [main] > > org.apache.catalina.core.JniLifecycleListener.lifecycleEvent Loaded native > > library opencv_java343 > > 22-Oct-2018 18:45:04.759 INFO [main] > > org.apache.catalina.core.JniLifecycleListener.lifecycleEvent Loaded native > > library opencv_java343 Okay. > Then I modified ROOT.xml, context_1.xml, and context_2.xml, one at a time: > > > 22-Oct-2018 18:45:51.692 INFO > > [ContainerBackgroundProcessor[StandardEngine[Catalina]]] > > org.apache.catalina.core.JniLifecycleListener.lifecycleEvent Loaded native > > library opencv_java343 > > [...] > > 22-Oct-2018 18:46:01.803 INFO > > [ContainerBackgroundProcessor[StandardEngine[Catalina]]] > > org.apache.catalina.core.JniLifecycleListener.lifecycleEvent Loaded native > > library opencv_java343 Interesting. I didn't realize that the JVM binds the native library to a specific ClassLoader and, does one of two things if the library has alreayd been loaded: 1. Ignores the call (if in the same ClassLoader; says so in javadoc for Runtime.loadLibrary) 2. Throws an UnsatisfiedLinkError complaining that the library is already loaded from a different ClassLoader. The Java spec[1] has something odd to say about native lirbaries and ClassLoaders, though it's still a little unclear: " The programmer may use a single library to store all the native methods needed by any number of classes, as long as these classes are to be loaded with the same class loader. The VM internally maintains a list of loaded native libraries for each class loader. " I guess "same class loader" can also mean "or a child class loader" since it's evidently working for you. But the point is that you need to consistently (re)load the native library into the same classloader if you don't want to throw any errors. [1] https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/design.html#jni_interface_functions_and_pointers -- You are receiving this mail because: You are the assignee for the bug. --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org