简体   繁体   English

JNLP不合作JFileChooser访问被拒绝

[英]JNLP isn't cooperating JFileChooser Access Denied

I feel really dumb...... 我真的很傻......

So I am writing a Java app, and if you can help me get this to work you'll be able to see it. 因此,我正在编写一个Java应用程序,如果您可以帮助我使其正常运行,您将能够看到它。

so my jar file is here: http://team2648.com/OTIS2/admin/OmniNode2.8.jar 所以我的jar文件在这里: http : //team2648.com/OTIS2/admin/OmniNode2.8.jar

I would like it to be able to be used as a Java web-start application, i was following the tutorial here: http://download.oracle.com/javase/tutorial/deployment/webstart/deploying.html 我希望它能够用作Java Web启动应用程序,我在这里遵循以下教程: http : //download.oracle.com/javase/tutorial/deployment/webstart/deploying.html

so I wrote the following JNLP file as directed: 所以我按照指示编写了以下JNLP文件:

<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" 
codebase="http://team2648.com/OTIS2/admin" 
href="test.jnlp">
<information>
    <title>OmniNode Mapper</title>
    <vendor>Techplex Engineer</vendor>
</information>
<resources>
    <!-- Application Resources -->
    <j2se version="1.6+"
      href="http://java.sun.com/products/autodl/j2se"/>
    <jar href="OmniNode2.8.jar" main="true" />

</resources>
<application-desc
     name="OmniNode Mapper"
     main-class="omninode28.Driver"
     width="300"
     height="300">
 </application-desc>
 <update check="background"/>
</jnlp>

But as you'll see if you download the jnlp http://team2648.com/OTIS2/admin/test.jnlp 但是,您将看到是否下载了jnlp http://team2648.com/OTIS2/admin/test.jnlp
and run it, We get the following error(On a PC): 并运行它,我们得到以下错误(在PC上):

access denied (java.io.FilePermission C:\Users\MyUserName\Documents read)

Exception 例外

java.security.AccessControlException: access denied (java.io.FilePermission C:\\Users\\Techplex Engineer\\Documents read) java.security.AccessControlException:访问被拒绝(java.io.FilePermission C:\\ Users \\ Techplex Engineer \\ Documents读取)
at java.security.AccessControlContext.checkPermission(Unknown Source) 在java.security.AccessControlContext.checkPermission(未知源)
at java.security.AccessController.checkPermission(Unknown Source) 在java.security.AccessController.checkPermission(未知源)
at java.lang.SecurityManager.checkPermission(Unknown Source) 在java.lang.SecurityManager.checkPermission(未知源)
at java.lang.SecurityManager.checkRead(Unknown Source) 在java.lang.SecurityManager.checkRead(未知来源)
at java.io.File.exists(Unknown Source) 在java.io.File.exists(未知来源)
at java.io.Win32FileSystem.canonicalize(Unknown Source) 在java.io.Win32FileSystem.canonicalize(未知源)
at java.io.File.getCanonicalPath(Unknown Source) 在java.io.File.getCanonicalPath(未知来源)
at sun.awt.shell.Win32ShellFolderManager2.createShellFolder(Unknown Source) 在sun.awt.shell.Win32ShellFolderManager2.createShellFolder(来源不明)
at sun.awt.shell.Win32ShellFolderManager2.getPersonal(Unknown Source) 在sun.awt.shell.Win32ShellFolderManager2.getPersonal(来源不明)
at sun.awt.shell.Win32ShellFolderManager2.get(Unknown Source) 在sun.awt.shell.Win32ShellFolderManager2.get(未知来源)
at sun.awt.shell.ShellFolder.get(Unknown Source) 在sun.awt.shell.ShellFolder.get(未知来源)
at javax.swing.filechooser.FileSystemView.getDefaultDirectory(Unknown Source) 在javax.swing.filechooser.FileSystemView.getDefaultDirectory(未知来源)
at javax.swing.JFileChooser.setCurrentDirectory(Unknown Source) 在javax.swing.JFileChooser.setCurrentDirectory(未知来源)
at javax.swing.JFileChooser.(Unknown Source) 在javax.swing.JFileChooser中。(未知源)
at javax.swing.JFileChooser.(Unknown Source) 在javax.swing.JFileChooser中。(未知源)
at omninode28.NodePanel.(NodePanel.java:61) 在omninode28.NodePanel。(NodePanel.java:61)
at omninode28.EditPanel.(EditPanel.java:31) 在omninode28.EditPanel。(EditPanel.java:31)
at omninode28.Driver.main(Driver.java:25) 在omninode28.Driver.main(Driver.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 在sun.reflect.NativeMethodAccessorImpl.invoke(未知来源)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 在sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源)
at java.lang.reflect.Method.invoke(Unknown Source) 在java.lang.reflect.Method.invoke(未知来源)
at com.sun.javaws.Launcher.executeApplication(Unknown Source) 在com.sun.javaws.Launcher.executeApplication(未知来源)
at com.sun.javaws.Launcher.executeMainClass(Unknown Source) 在com.sun.javaws.Launcher.executeMainClass(未知来源)
at com.sun.javaws.Launcher.doLaunchApp(Unknown Source) 在com.sun.javaws.Launcher.doLaunchApp中(未知来源)
at com.sun.javaws.Launcher.run(Unknown Source) 在com.sun.javaws.Launcher.run(未知来源)
at java.lang.Thread.run(Unknown Source) 在java.lang.Thread.run(未知来源)

So those files it points at: 因此,这些文件指向:

this line: fc = new JFileChooser(); 这行:fc = new JFileChooser();

So this leads me to believe that i need to ask the user permission to write to their system. 因此,这使我相信我需要征得用户的许可才能写入他们的系统。

I am befuddled. 我很困惑。 Any help would be super, Thanks 任何帮助都将是超级,谢谢

Edit... Should I just make users download the Jar directly? 编辑...我应该让用户直接下载Jar吗? pros cons? 优点缺点?

you have to sign the jars and grant permission to the classes by adding this snippet into the jnlp: 您必须通过将以下代码段添加到jnlp中来对jar进行签名并授予对类的权限:

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

Obviously it would be a bad idea for any website you browsed across to be able to read from your local filesystem. 显然,这对于您浏览过的任何网站都能够从本地文件系统读取信息都是一个坏主意。 So it isn't allowed directly. 因此,不允许直接使用。

Perhaps the best way around this is to use the FileOpenService . 解决此问题的最佳方法可能是使用FileOpenService This gives applications a simple interface to a file chooser of some description that can open (read and, unfortunately, write) user selected files without giving direct access to the file system. 这为应用程序提供了一个具有某种描述的文件选择器的简单界面,该文件选择器可以打开(读取和不幸地写入)用户选择的文件,而无需直接访问文件系统。

一种可能性是,您的罐子没有按此处所述签名

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM