为什么我的小程序在通过 JavaScript 访问方法时无法加载本机库?

发布于 2024-11-29 09:42:28 字数 2452 浏览 2 评论 0原文

我有一个用于扫描文档的小程序(使用 JTwain)。我的小程序由我编写的一个 jar、几个第三方 jar 和一个 dll(包装在 JTwain jar 中)组成。我打算加载小程序,然后使用 JavaScript 访问小程序方法。然而,当我这样做时,我遇到了一个安全异常:

java.security.AccessControlException: access denied (java.lang.RuntimePermission loadLibrary.AspriseJTwain)
    at java.security.AccessControlContext.checkPermission(Unknown Source)
    at java.security.AccessController.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkLink(Unknown Source)
    at java.lang.Runtime.loadLibrary0(Unknown Source)
    at java.lang.System.loadLibrary(Unknown Source)
    at com.asprise.util.jtwain.SourceManager.init(SourceManager.java:222)
    at com.asprise.util.jtwain.SourceManager.<init>(SourceManager.java:36)
    at com.asprise.util.jtwain.SourceManager.instance(SourceManager.java:28)
    at co.altcom.cache.scanner.CacheScan.scanToPDF(CacheScan.java:91)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at sun.plugin.javascript.JSInvoke.invoke(Unknown Source)
    at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at sun.plugin.javascript.JSClassLoader.invoke(Unknown Source)
    at sun.plugin2.liveconnect.JavaClass$MethodInfo.invoke(Unknown Source)
    at sun.plugin2.liveconnect.JavaClass$MemberBundle.invoke(Unknown Source)
    at sun.plugin2.liveconnect.JavaClass.invoke0(Unknown Source)
    at sun.plugin2.liveconnect.JavaClass.invoke(Unknown Source)
    at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo$DefaultInvocationDelegate.invoke(Unknown Source)
    at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo.doObjectOp(Unknown Source)
    at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo$LiveConnectWorker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

让我感到困惑的是,我可以在小程序 init 方法中很好地运行这些函数(没有例外 - 小程序扫描并保存到计算机文件系统)。只有当它们被 JavaScript 访问时它们才会失败。我猜我需要制定一些政策,但我找不到任何相关内容。

有什么想法吗?

I have an applet for scanning documents (using JTwain). My applet is made up of a jar I wrote, a couple of third party jars, and a dll (wrapped in the JTwain jar). I intend to load the applet, then access the applets methods using JavaScript. However I get a security exception when I do this:

java.security.AccessControlException: access denied (java.lang.RuntimePermission loadLibrary.AspriseJTwain)
    at java.security.AccessControlContext.checkPermission(Unknown Source)
    at java.security.AccessController.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkLink(Unknown Source)
    at java.lang.Runtime.loadLibrary0(Unknown Source)
    at java.lang.System.loadLibrary(Unknown Source)
    at com.asprise.util.jtwain.SourceManager.init(SourceManager.java:222)
    at com.asprise.util.jtwain.SourceManager.<init>(SourceManager.java:36)
    at com.asprise.util.jtwain.SourceManager.instance(SourceManager.java:28)
    at co.altcom.cache.scanner.CacheScan.scanToPDF(CacheScan.java:91)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at sun.plugin.javascript.JSInvoke.invoke(Unknown Source)
    at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at sun.plugin.javascript.JSClassLoader.invoke(Unknown Source)
    at sun.plugin2.liveconnect.JavaClass$MethodInfo.invoke(Unknown Source)
    at sun.plugin2.liveconnect.JavaClass$MemberBundle.invoke(Unknown Source)
    at sun.plugin2.liveconnect.JavaClass.invoke0(Unknown Source)
    at sun.plugin2.liveconnect.JavaClass.invoke(Unknown Source)
    at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo$DefaultInvocationDelegate.invoke(Unknown Source)
    at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo.doObjectOp(Unknown Source)
    at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo$LiveConnectWorker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

What's throwing me is that I can run these functions from within the applets init method just fine (no exceptions - the applet scans and saves to the computers file system). It's only when they're accessed by JavaScript that they fail. I'm guessing there's some policy I need to set, but I can't find anything about it.

Any ideas?

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

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

发布评论

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

评论(1

一笔一画续写前缘 2024-12-06 09:42:28

将 JS 调用的代码包装在 AccessController.doPrivileged(PrivilegedAction) (或重载变体)中。

Wrap the code called by JS in an AccessController.doPrivileged(PrivilegedAction) (or overloaded variant).

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