开发者

A proper way to use native libraries in JNA with Applet deployed by JWS (java web start)

I am using an applet deployed through JWS (Java Web Start). This applet has some native functionality included: JNA. User32, Kernel32 and Gdi32. When I launch the applet through JWS, I get the following:

basic: LD - All JAR files signed: file:/C:/JavaApplication6/dist/launch.jnlp
basic: passing security checks; secureArgs:false, allSigned:false
basic: continuing launch in this VM
network: LDUpdater: started background update check
basic: JNLP2ClassLoader.findClass: winToJnaApi.NewApplet: try again ..
basic: JNLP2ClassLoader.getPermissions() ..
basic: Plugin2ClassLoader.getPermissions CeilingPolicy allPerms
security: JAVAWS AppPolicy Permission requested for: file:/C:/JavaApplication6/dist/JavaApplication6.jar
basic: JNLP2ClassLoader.getPermissions() X
basic: Applet loaded.
basic: Applet resized and added to parent container
basic: PERF: AppletExecutionRunnable - applet.init() BEGIN ; jvmLaunch dt 194323 us, pluginInit dt 462062 us, TotalTime: 656385 us
basic: JNLP2ClassLoader.findClass: winToJnaApi.APIManipulation: try again ..
basic: JNLP2ClassLoader.findClass: winToJnaApi.User32Extended: try again ..
basic: JNLP2ClassLoader.findClass: com.sun.jna.win32.StdCallLibrary$StdCallCallback: try again ..
basic: JNLP2ClassLoader.getPermissions() ..
basic: Plugin2ClassLoader.getPermissions CeilingPolicy allPerms
security: JAVAWS AppPolicy Permission requested for: file:/C:/JavaApplication6/dist/lib/jna.jar
basic: JNLP2ClassLoader.getPermissions() X
basic: JNLP2ClassLoader.findClass: com.sun.jna.Callback: try again ..
basic: JNLP2ClassLoader.findClass: com.sun.jna.win32.StdCall: try again ..
basic: JNLP2ClassLoader.findClass: com.sun.jna.AltCallingConvention: try again ..
basic: JNLP2ClassLoader.findClass: com.sun.jna.Library: try again ..
basic: JNLP2ClassLoader.findClass: com.sun.jna.Native: try again ..
basic: JNLP2ClassLoader.findClass: com.sun.jna.Callback$UncaughtExceptionHandler: try again ..
basic: JNLP2ClassLoader.findClass: com.sun.jna.Native$3: try again ..

This is strange, correct? If I check my jars with jarsigner, they seem to be all signed (I use automatic signing by Netbeans but it doesn't work even if i sign them manually). As I am pretty new to applet and JWS technology, I wonder if the try again... means JNLP could not find the appropriate class.

What is even stranger is that if I define a native method in the applet, for example a method that upon clicking a button on the applet is giving me a Windows messa开发者_Python百科ge box, it works if i click the button on the applet, but if i try to invoke the same function through javascript it fails. So here is my .jnlp file:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <jnlp codebase="file:/C:/JavaApplication6/dist/" href="launch.jnlp" spec="1.0+">
        <information>
            <title>JavaApplication6</title>
            <description>blalbla</description>
            <description kind="short">JavaApplication6</description>

        </information>
    <update check="background"/>
    <security>
    <all-permissions/>
    </security>
        <resources>
    <j2se java-vm-args="-Djava.security.policy=applet.policy" version="1.5+"/>
    <jar href="JavaApplication6.jar" main="true"/>


        <jar href="lib/jna.jar"/>
    <jar href="lib/platform.jar"/>
    </resources>
        <applet-desc height="300" main-class="winToJnaApi.NewApplet" name="JavaApplication6" width="300">

        </applet-desc>
    </jnlp>

According to some info I found I should convert user32_x86 directory of the jna.jar into a jar on its own and include it as a nativelib href in my jnlp, but it doesn't work. Also, trying to wrap every call to the native functions in the applet with doPrivileged doesn't work either.

Any help would be appreciated


I did manage to get rid of the Try again messages.

What the problem is is that JWS has some problems if its archive and/or codebase jars are not signed by the same authority. With me, the problem was i was using BouncyCastle and it was already signed. I unsigned it using jarsigner and then let Netbeans sign all jars for me. If you don't unsign the signed libs, Netbeans will skip them and as a result JWS will complain. So, don't use jarsigner only to verify IF your jars are signed, use jarsigner on all your jars to find who signed them. If there are mismatches, you will get this message. Cheers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜