Forcing Jetty to load classes in the parent ClassLoader

隐身守侯 提交于 2019-12-08 07:34:06

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/8011643/forcing-jetty-to-load-classes-in-the-parent-classloader

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!