Java - 如何在 Java Web Start 中获取权限
您好,我成功地为我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要对 JNLP 文件进行签名并配置
元素,如 此处。You need to sign your JNLP file and configure the
<security>
element, as discussed here.将以下内容添加到您的 JNLP:
这将弹出一个对话框,要求用户为您的应用程序授予必要的权限。
Add the following to your JNLP:
This will pop a dialogue asking the user the give the necessary permission to your app.
如果您想访问文件系统,您需要更改 JNLP 文件以包括:
这还要求您对 jar 文件进行签名。
另一种选择是将文件作为资源打包在 jar 内,而您不必执行所有这些操作。
If you want access to the file system you need to change your JNLP file to include:
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.