通过 JWS 部署的 Applet 在 JNA 中使用本机库的正确方法(java web start)

发布于 2024-10-01 13:07:31 字数 3329 浏览 9 评论 0原文

我正在使用通过 JWS(Java Web Start)部署的小程序。该小程序具有一些本机功能,包括:JNA。 User32、Kernel32 和 Gdi32。当我通过 JWS 启动小程序时,我得到以下信息:

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 ..

这很奇怪,对吗?如果我用 jarsigner 检查我的 jar,它们似乎都已签名(我使用 Netbeans 自动签名,但即使我手动签名也不起作用)。由于我对小程序和 JWS 技术相当陌生,我想知道重试...是否意味着 JNLP 找不到合适的类。

更奇怪的是,如果我在小程序中定义一个本机方法,例如,单击小程序上的按钮后会出现一个 Windows 消息框的方法,如果我单击小程序上的按钮,它会起作用,但如果我尝试通过 javascript 调用相同的函数,但失败了。所以这是我的 .jnlp 文件:

<?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>

根据我发现的一些信息,我应该将 jna.jar 的 user32_x86 目录转换为自己的 jar 并将其作为 nativelib href 包含在我的 jnlp 中,但它不起作用。此外,尝试使用 doPrivileged 包装对小程序中本机函数的每个调用也不起作用。

任何帮助将不胜感激

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 message 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

软甜啾 2024-10-08 13:07:31

我确实设法摆脱了“重试”消息。

问题是,如果 JWS 的存档和/或代码库 jar 没有由同一机构签名,那么 JWS 就会出现一些问题。对我来说,问题是我正在使用 BouncyCastle 并且它已经签名了。我使用 jarsigner 取消签名,然后让 Netbeans 为我签署所有 jar。如果您不取消签名已签名的库,Netbeans 将跳过它们,因此 JWS 会抱怨。因此,不要仅使用 jarsigner 来验证您的 jar 是否已签名,而是在所有 jar 上使用 jarsigner 来查找谁签署了它们。如果不匹配,您将收到此消息。干杯。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文