强制Jetty加载父ClassLoader中的类 [英] Forcing Jetty to load classes in the parent ClassLoader

查看:365
本文介绍了强制Jetty加载父ClassLoader中的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从本机代码启动JVM,然后启动Jetty。然后,webapp会加载一个名为JPeripheral的库。本机启动器和JPeripheral都依赖于一个名为Jace的本机库。当webapp尝试加载Jace Java抛出时:

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:本机库jace.dll已经加载到另一个类加载器中

这是webapp中的ClassLoader层次结构:

Here is the ClassLoader hierarchy inside the webapp:

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

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

Jace.dll和Jetty都由 sun.misc.Launcher $ AppClassLoader加载(由本机启动器使用)。
JPeripheral由WebAppClassLoader加载。

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

解决此问题的一种方法是从 sun.misc.Launcher $ AppClassLoader加载JPeripheral (因此jace.dll从同一个Classloader加载两次)。我该怎么做?

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?

推荐答案

事实证明你可以使用WebAppContext.addSystemClass强制WebAppClassLoader从父ClassLoader加载JPeripheral ()。在我的情况下 WebAppContext.addSystemClass(org.jperipheral。)做了这个伎俩。

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.

这篇关于强制Jetty加载父ClassLoader中的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆