BTJ
BTJ

Reputation: 11

UnsatisfiedLinkError + JNLP + Applet + DLL

I have created a JNLP to load the applet and some native DLL files. Following are the codes of each components

JNLP

<?xml version="1.0" encoding="UTF-8"?>
<!-- href attribute contains relative path;
     codebase attribute not specified -->
<jnlp href="myKad.jnlp">
    <information>
        <title>MyKad Reader Applet</title>
        <vendor>MyKad</vendor>
    </information>
    <security>
        <all-permissions/>
    </security>
    <resources>
        <!-- Application Resources -->
        <j2se version="1.6+" href="http://java.sun.com/products/autodl/j2se" />
        <jar href="HLB_Mykad-0.0.1-SNAPSHOT.jar" main="true"/>
        <nativelib href="HLB_Mykad-0.0.1-SNAPSHOT.jar" download="eager"/>
    </resources>
    <applet-desc
            name="MyKad Applet"
            main-class="com.glexim.applet.GleximApplet"
            width="1"
            height="1">
    </applet-desc>
    <update check="background"/>
</jnlp>

JAR (HLB_Mykad-0.0.1-SNAPSHOT.jar) Structure (JAR's are Packaged at top lavel)

com.glexim.applet.GleximApplet
META-INF
Sample.dll

HTML Code

<applet jnlp_href="./applet/myKad.jnlp"
code="com.glexim.applet.GleximApplet" id="gleximApplet"
mayscript="true" width="0px" style="" />

While loading applet I am getting following exception in applet console:

java.lang.RuntimeException: java.lang.UnsatisfiedLinkError: no Sample in java.library.path
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.UnsatisfiedLinkError: no Sample in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at com.glexim.zf1.MyKad$1.run(MyKad.java:19)
at java.security.AccessController.doPrivileged(Native Method)
at com.glexim.zf1.MyKad.<clinit>(MyKad.java:13)
at com.glexim.applet.GleximApplet.<init>(GleximApplet.java:43)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$12.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$400(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Exception: java.lang.RuntimeException: java.lang.UnsatisfiedLinkError: no Sample in java.library.path

My Applet is signed applet and all the DLL files inside applet are also signed with same signature.

Upvotes: 1

Views: 2516

Answers (1)

Gilberto Torrezan
Gilberto Torrezan

Reputation: 5277

Create other section in your JNLP file describing the native resources:

<resources os="Windows" arch="x86">
    <nativelib href="jar-with-nativelibs.jar"/>
</resources>

(You don't have to use one jar for each os and architecture supported, but it's recommended)

And after that, define the java.library.path property:

<property key="java.library.path" value="." />

And you're good to go.

Upvotes: 1

Related Questions