开发者

Java - How to get permission in Java Web Start

开发者 https://www.devze.com 2023-02-09 18:42 出处:网络
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

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.s开发者_运维技巧wing.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


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


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.


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.

0

精彩评论

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