简体   繁体   中英

Forcing Jetty to load classes in the parent ClassLoader

I launch a JVM from native code, then launch Jetty. A webapp then loads a library called JPeripheral. Both the native launcher and JPeripheral depend a native library called Jace. When the webapp tries loading Jace Java throws:

java.lang.UnsatisfiedLinkError: Native Library jace.dll already loaded in another classloader

Here is the ClassLoader hierarchy inside the webapp:

WebAppClassLoader -> sun.misc.Launcher$AppClassLoader -> sun.misc.Launcher$ExtClassLoader

Jace.dll and Jetty are both loaded by sun.misc.Launcher$AppClassLoader (used by the native launcher). JPeripheral is loaded by WebAppClassLoader.

One way to solve this problem would be to load JPeripheral from sun.misc.Launcher$AppClassLoader (so jace.dll gets loaded twice from the same Classloader). How do I do that?

It turns out that you can force WebAppClassLoader to load JPeripheral from the parent ClassLoader using WebAppContext.addSystemClass(). In my case WebAppContext.addSystemClass("org.jperipheral.") did the trick.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM