Reputation: 477
I need to create a Java applet which loads a local DLL. It works fine, but only the first time. If I refresh the page, it always complains by throwing the following exception:
Exception: java.lang.RuntimeException: java.lang.UnsatisfiedLinkError: Native Library E:\test.dll already loaded in another classloader
Any ideas on how I can fix this?
Here is my code:
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);
}
}
}
And the applet code:
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();
}
}
I have read a lot on this issue but still can't find a solution. Can anyone help? Thanks in advance.
Upvotes: 1
Views: 4025
Reputation: 3142
I resolved the same issue by adding following snippet to the applet tag on the html page.
<param name="classloader_cache" value="false">
I have following param in the applet's JNLP file. That might be also relevant.
<applet-desc ...>
<param name="separate_jvm" value="true"/>
</applet-desc>
Upvotes: 1
Reputation: 19443
This article seems to provide some good advise to make sure you get the same ClassLoader
for each applet invocation.
Upvotes: 3