Forcing Jetty to load classes in the parent ClassLoader

I start the JVM from my own code and then run Jetty. Webapp then downloads the JPeripheral library. Both the native launcher and JPeripheral depend on their own Jace library. When the webapp attempt tries to load jace java throws:

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

Here is the ClassLoader hierarchy inside webapp:

WebAppClassLoader → sun.misc.Launcher $ AppClassLoader → sun.misc.Launcher $ ExtClassLoader

Jace.dll and Jetty are loaded using sun.misc.Launcher$AppClassLoader (used by the built-in launcher). JPeripheral is loaded by WebAppClassLoader.

One way to solve this problem is to download JPeripheral from sun.misc.Launcher$AppClassLoader (therefore jace.dll is loaded twice from the same Classloader twice). How to do it?

+1
source share
1 answer

Turns out you can force WebAppClassLoader to load JPeripheral from the parent class ClassLoader using WebAppContext.addSystemClass (). In my case, WebAppContext.addSystemClass("org.jperipheral.") Did the trick.

+1
source

Source: https://habr.com/ru/post/915593/


All Articles