Java - 如何在 Java Web Start 中获取权限

发布于 2024-10-16 08:50:37 字数 1304 浏览 4 评论 0原文

您好,我成功地为我的 Java 应用程序创建了 jar 和 .jnlp 文件,但在运行时遇到了麻烦。使用 Java Web Start 启动正常,但我想我需要做点什么 像平常一样,当我运行它时,它不会请求访问 HD 进行文件 I/O 的权限。

希望得到一些帮助和建议,以了解如何获得许可权,即我必须做什么,这是我必须对所有班级做的事情,但不确定。错误 我在 Java Web Start 中收到的消息如下。

Exception in thread "AWT-EventQueue-0" java.security.AccessControlException: 
  access denied (java.io.FilePermission StockDatabase;Stocks.dat read)
    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.checkRead(Unknown Source)
    at java.io.File.exists(Unknown Source)
    at StockCodeDatabase.<init>(OptraderSA.java:782)
    at OptraderSA.actionPerformed(OptraderSA.java:136)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.AbstractButton.doClick(Unknown Source)
    at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
    at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unkno

Hi managed to create the jar and .jnlp files for my Java application but running into trouble when it runs. Launches okay with Java Web Start but I think I need to do something
extra as normally when I run it it doesn't ask for permission to access the HD for file I/O.

Would appreciate some help and advise to know what to do to get the permission rights i.e. what do I have to do is it something I have to do to all my classes not sure. The error
message I get in Java Web Start is as below.

Exception in thread "AWT-EventQueue-0" java.security.AccessControlException: 
  access denied (java.io.FilePermission StockDatabase;Stocks.dat read)
    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.checkRead(Unknown Source)
    at java.io.File.exists(Unknown Source)
    at StockCodeDatabase.<init>(OptraderSA.java:782)
    at OptraderSA.actionPerformed(OptraderSA.java:136)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.AbstractButton.doClick(Unknown Source)
    at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
    at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unkno

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

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

发布评论

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

评论(3

半边脸i 2024-10-23 08:50:37

您需要对 JNLP 文件进行签名并配置 元素,如 此处

You need to sign your JNLP file and configure the <security> element, as discussed here.

﹎☆浅夏丿初晴 2024-10-23 08:50:37

将以下内容添加到您的 JNLP:

<security>
  <all-permissions/>
</security>

这将弹出一个对话框,要求用户为您的应用程序授予必要的权限。

Add the following to your JNLP:

<security>
  <all-permissions/>
</security>

This will pop a dialogue asking the user the give the necessary permission to your app.

把梦留给海 2024-10-23 08:50:37

如果您想访问文件系统,您需要更改 JNLP 文件以包括:

<security><all-permissions/></security>

这还要求您对 jar 文件进行签名。

另一种选择是将文件作为资源打包在 jar 内,而您不必执行所有这些操作。

If you want access to the file system you need to change your JNLP file to include:

<security><all-permissions/></security>

This requires you to also sign your jar files.

Another option is to package the file inside the jar as a resource and you don't have to do all that.

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