Java applet问题:dll已加载到另一个类加载器中



我需要创建一个加载本地DLL的Java applet。它很好,但只是第一次。如果我刷新页面,它总是通过抛出以下异常来抱怨:

Exception: java.lang.RuntimeException: java.lang.UnsatisfiedLinkError: Native Library E:test.dll already loaded in another classloader

有什么办法可以解决这个问题吗?

下面是我的代码:
public class NativeWrapper
{
    public native String GetIP();
    public NativeWrapper(final String nativeLib) {
        try {
            System.load(nativeLib);
        } catch (UnsatisfiedLinkError e) {
            System.out.println("UnsatisfiedLinkError exception" + e);
        }
    }
}

和applet代码:

public class MyApplet extends Applet {
    private static NativeWrapper dll = new NativeWrapper("e:/test.dll");
    public MyApplet () {
    }
    // to be called by javascript on html page
    public string GetIPAddress() {
        return dll.GetIP();
    }
}
我读了很多关于这个问题的书,但仍然找不到解决办法。有人能帮忙吗?

本文似乎提供了一些很好的建议,以确保每次applet调用都获得相同的ClassLoader

我通过在html页面的applet标签中添加以下代码片段来解决相同的问题。

<param name="classloader_cache" value="false">

在applet的JNLP文件中有以下参数。这可能也是相关的。

<applet-desc ...>
    <param name="separate_jvm" value="true"/>
</applet-desc>