Java - How to get permission in Java Web Start

2019-01-20 13:25发布

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

3条回答
孤傲高冷的网名
2楼-- · 2019-01-20 13:47

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.

查看更多
太酷不给撩
3楼-- · 2019-01-20 13:55

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

查看更多
时光不老,我们不散
4楼-- · 2019-01-20 13:55

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.

查看更多
登录 后发表回答