JNLP Applet UnsatisfiedLinkError

时间:2014-01-21 14:41:40

标签: java dll applet jnlp unsatisfiedlinkerror

我正在尝试使用JNLP构建一个applet。我写了一个Ant脚本来编译java类,构建jar文件并签名。我用Ant建立的同一个密钥库签署了所有罐子。我在Java控制面板中允许显示自签名小程序。如果我直接运行JNLP文件,一切都运行良好,但如果我把这个applet放在一个网页中,我会得到UnsatisfiedLinkError。

这是我得到的错误:

java.lang.reflect.InvocationTargetException
    at java.awt.EventQueue.invokeAndWait(Unknown Source)
    at java.awt.EventQueue.invokeAndWait(Unknown Source)
    at javax.swing.SwingUtilities.invokeAndWait(Unknown Source)
    at polygon.Example.init(Unknown Source)
    at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.init(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.UnsatisfiedLinkError: no gluegen-rt 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.jogamp.common.jvm.JNILibLoaderBase.loadLibraryInternal(JNILibLoaderBase.java:454)
    at com.jogamp.common.jvm.JNILibLoaderBase.access$000(JNILibLoaderBase.java:59)
    at com.jogamp.common.jvm.JNILibLoaderBase$DefaultAction.loadLibrary(JNILibLoaderBase.java:90)
    at com.jogamp.common.jvm.JNILibLoaderBase.loadLibrary(JNILibLoaderBase.java:328)
    at com.jogamp.common.os.DynamicLibraryBundle$GlueJNILibLoader.loadLibrary(DynamicLibraryBundle.java:390)
    at com.jogamp.common.os.Platform$2.run(Platform.java:249)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.jogamp.common.os.Platform.loadGlueGenRTImpl(Platform.java:231)
    at com.jogamp.common.os.Platform.<clinit>(Platform.java:183)
    at javax.media.opengl.GLProfile.<clinit>(GLProfile.java:99)
    ...

我根据操作系统构建的每个jar文件都包含gluegen-rt.dll但无法加载它。我的本机库的Jar文件由DLL文件组成。它看起来像:

  • win64.jar
    • gluegen-rt.dll
    • jogl_cl.dll

我的文件夹层次结构如下:

  • 的WebContent
    • applet.jnlp
    • 小应用程序
      • applet.jar
      • 其他一些jar文件......
      • LIB
      • 天然
        • win32.jar

这是我的Ant脚本:

<project name="Project" default="signJar">
<path id="libraries.path">
    <fileset dir="${lib.dir}" includes="**/*.jar"/>
</path>

<path id="maps.path">
    <fileset dir="${maps.dir}"/>
</path>

<target name="clean">
    <delete dir="${classes.dir}" />
    <delete dir="${jar.dir}" />
    <delete dir="${build.dir}" />
</target>

<target name="init" depends="clean">
    <mkdir dir="${build.dir}" />
    <mkdir dir="${classes.dir}" />
    <mkdir dir="${dist.dir}" />
</target>

<target name="compile" depends="init">
    <javac srcdir="${src.dir}" destdir="${classes.dir}" includeantruntime="true" verbose="true" classpathref="libraries.path" encoding="ISO-8859-9" />
</target>

<target name="dist" depends="compile">

    <pathconvert property="mf.classpath" pathsep=" ">
        <path refid="libraries.path" />
        <flattenmapper />
    </pathconvert>

    <tstamp/><!-- needed for TODAY -->
    <manifest file="MANIFEST.MF">
        <attribute name="Built-By" value="${manifest.built.by}"/>
        <attribute name="Created-By" value="${manifest.created.by}"/>
        <attribute name="Main-Class" value="polygon.MainApplet"/>
        <attribute name="Implementation-Version" value="${version.number}-b${build.number}"/>   
        <attribute name="Built-Date" value="${TODAY}" />
        <attribute name="Class-Path" value="${maps.dir} ${mf.classpath}" />
        <attribute name="Permissions" value="all-permissions" />
        <attribute name="Codebase" value="*" />
        <attribute name="Application-Name" value="Applet Application in Manifest" />
        <attribute name="Trusted-Only" value="true" />
    </manifest>

    <jar jarfile="${dist.dir}/applet.jar" basedir="${classes.dir}" manifest="MANIFEST.MF" />

    <jar jarfile="${dist.dir}/${native.libraries.dir}/linux.jar" basedir="${native.libraries.dir}/linux" />
    <jar jarfile="${dist.dir}/${native.libraries.dir}/linux64.jar" basedir="${native.libraries.dir}/linux64" />
    <jar jarfile="${dist.dir}/${native.libraries.dir}/macos_64.jar" basedir="${native.libraries.dir}/macos_64" />
    <jar jarfile="${dist.dir}/${native.libraries.dir}/macos_ppc.jar" basedir="${native.libraries.dir}/macos_ppc" />
    <jar jarfile="${dist.dir}/${native.libraries.dir}/macos_x86.jar" basedir="${native.libraries.dir}/macos_x86" />
    <jar jarfile="${dist.dir}/${native.libraries.dir}/solaris_amd64.jar" basedir="${native.libraries.dir}/solaris_amd64" />
    <jar jarfile="${dist.dir}/${native.libraries.dir}/solaris_i586.jar" basedir="${native.libraries.dir}/solaris_i586" />
    <jar jarfile="${dist.dir}/${native.libraries.dir}/solaris_sparc.jar" basedir="${native.libraries.dir}/solaris_sparc" />
    <jar jarfile="${dist.dir}/${native.libraries.dir}/solaris_sparc64.jar" basedir="${native.libraries.dir}/solaris_sparc64" />
    <jar jarfile="${dist.dir}/${native.libraries.dir}/win32.jar" basedir="${native.libraries.dir}/win32" />
    <jar jarfile="${dist.dir}/${native.libraries.dir}/win64.jar" basedir="${native.libraries.dir}/win64" />

    <jar jarfile="${dist.dir}/maps.jar" basedir="${lib.dir}/maps" />

    <copy todir="${dist.dir}">
        <fileset dir="${lib.dir}">
            <include name="*.jar"/>
        </fileset>
    </copy>

</target>

<target name="signJar" depends="dist">
    <delete dir="${dist.dir}/.keystore" />

    <genkey alias="keystorealias" verbose="true" storepass="storepass" 
            keypass="keypass"
            validity="365"
            keystore="${dist.dir}/.keystore">
            <dname>
                <param name="CN" value="CN"/>
                <param name="OU" value="OU"/>
                <param name="O"  value="O"/>
                <param name="C"  value="TR"/>
            </dname>
        </genkey>

        <signjar
            alias="keystorealias" keystore="${dist.dir}/.keystore"
            storepass="storepass"
            keypass="keypass">
          <path>
            <fileset dir="${dist.dir}" includes="**/*.jar" />
          </path>
        </signjar>
    </target>
</project>

我没有写我的房产。我需要一些本地库来运行应用程序,正如您在Ant脚本中看到的那样,我根据操作系统将它们放入jar中。另外我在lib文件夹中需要一些其他jar文件,但我将它们放入Manifest文件中。我没有在JNLP文件中写它们。

这是我的JNLP:

<?xml version="1.0" encoding="UTF-8"?>

<jnlp spec="1.0+">
    <information>
        <title>Demo</title>
        <vendor>Team</vendor>
        <offline-allowed />
    </information>
    <security>
        <all-permissions/>
    </security>
    <resources>
        <j2se version="1.7+" initial-heap-size="256M" max-heap-size="512M" />

        <jar href="applet/applet.jar" main="true" />
        <jar href="applet/maps.jar" />
    </resources>

    <resources os="Linux" arch="x86">
        <nativelib href="applet/lib/native/linux_x86.jar" />
    </resources>

    <resources os="Linux" arch="amd64">
        <nativelib href="applet/lib/native/linux_x64.jar" />
    </resources>

    <resources os="Windows" arch="x86">
        <nativelib href="applet/lib/native/win32.jar" />
    </resources>

    <resources os="Windows" arch="amd64">
        <nativelib href="applet/lib/native/win64.jar" />
    </resources>

    <applet-desc name="Applet Application in Applet" main-class="polygon.Example" width="800" height="600" />
    <update check="background" policy="prompt-update" />
</jnlp>sources>

    <resources os="Linux" arch="x86">
        <nativelib href="applet/lib/native/linux_x86.jar" />
    </resources>

    <resources os="Linux" arch="amd64">
        <nativelib href="applet/lib/native/linux_x64.jar" />
    </resources>

    <resources os="Windows" arch="x86">
        <nativelib href="applet/lib/native/win32.jar" />
    </resources>

    <resources os="Windows" arch="amd64">
        <nativelib href="applet/lib/native/win64.jar" />
    </resources>

    <applet-desc name="Applet Application" main-class="polygon.Example" width="800" height="600" />
    <update check="background" policy="prompt-update" />
</jnlp>

此处是我的HTML代码,用于在网页中添加applet:

<applet width="800" height="500" codebase="applet" code="polygon.Example" archive="applet.jar">
<param name="jnlp_ref" value="applet.jnlp" />
</applet>

我尝试使用File类访问我的applet中的gluegen-rt.dll,我可以访问它。为什么我的applet可以加载本机库,如果我直接运行JNLP,为什么如果我把它放在网页中就无法加载它们?

请注意,我不希望将上面提到的库添加到计算机中的classpath中,因为如果不添加,则其他用户将无法运行它。因此无法将其添加到所有用户计算机中的类路径中。对我来说,这不是一个好的解决方案。

1 个答案:

答案 0 :(得分:0)

我发现它的原因是因为applet必须用不同的标签而不是applet标签添加。在我的情况下,我应该将applet标签更改为以下行以添加applet。

<script src="http://www.java.com/js/deployJava.js"></script>
<script>
    var attributes = {code: 'polygon.Example', width: 800, height: 600};
    var params = {jnlp_href: 'applet.jnlp'};
    deployJava.runApplet( attributes, params, '1.7' );
</script>