1

我创建了一个 JNLP 来加载小程序和一些本机 DLL 文件。以下是每个组件的代码

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) 结构(JAR 封装在顶层)

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

HTML 代码

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

加载小程序时,我在小程序控制台中遇到以下异常:

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

我的小程序是签名的小程序,小程序内的所有 DLL 文件也使用相同的签名进行签名。

4

1 回答 1

1

在您的 JNLP 文件中创建描述本机资源的其他部分:

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

(您不必为每个支持的操作系统和架构使用一个 jar,但建议使用)

之后,定义java.library.path属性:

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

你可以走了。

于 2013-01-16T19:25:42.593 回答