JNLP 不合作 JFileChooser 访问被拒绝

发布于 2024-09-26 10:04:38 字数 3271 浏览 0 评论 0原文

我觉得自己真的很蠢……

所以我正在编写一个Java应用程序,如果你能帮助我让它工作,你就能看到它。

所以我的 jar 文件在这里: http://team2648.com/OTIS2/admin/OmniNode2。 8.jar

我希望它能够用作 Java Web 启动应用程序,我正在遵循此处的教程:http://download.oracle.com/javase/tutorial/deployment/webstart/deploying.html

所以我按照指示编写了以下 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>

但正如您会看到的,如果您下载 jnlp http://team2648.com/OTIS2/admin/测试.jnlp
并运行它,我们得到以下错误(在PC上):

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

异常

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

所以它指向的那些文件:

这一行: fc = new JFileChooser();

所以这让我相信我需要请求用户许可才能写入他们的系统。

我很困惑。 任何帮助都会很棒, 谢谢

编辑... 我应该让用户直接下载 Jar 吗? 优点缺点?

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.

so my jar file is here: 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

so I wrote the following JNLP file as directed:

<?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
and run it, We get the following error(On a 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)
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 java.io.Win32FileSystem.canonicalize(Unknown Source)
at java.io.File.getCanonicalPath(Unknown Source)
at sun.awt.shell.Win32ShellFolderManager2.createShellFolder(Unknown Source)
at sun.awt.shell.Win32ShellFolderManager2.getPersonal(Unknown Source)
at sun.awt.shell.Win32ShellFolderManager2.get(Unknown Source)
at sun.awt.shell.ShellFolder.get(Unknown Source)
at javax.swing.filechooser.FileSystemView.getDefaultDirectory(Unknown Source)
at javax.swing.JFileChooser.setCurrentDirectory(Unknown Source)
at javax.swing.JFileChooser.(Unknown Source)
at javax.swing.JFileChooser.(Unknown Source)
at omninode28.NodePanel.(NodePanel.java:61)
at omninode28.EditPanel.(EditPanel.java:31)
at omninode28.Driver.main(Driver.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javaws.Launcher.executeApplication(Unknown Source)
at com.sun.javaws.Launcher.executeMainClass(Unknown Source)
at com.sun.javaws.Launcher.doLaunchApp(Unknown Source)
at com.sun.javaws.Launcher.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

So those files it points at:

this line: 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?
pros cons?

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

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

发布评论

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

评论(3

街道布景 2024-10-03 10:04:38

您必须通过将此代码段添加到 jnlp 中来签署 jar 并向类授予权限:

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

you have to sign the jars and grant permission to the classes by adding this snippet into the jnlp:

<security>
  <all-permissions/>
</security>
月亮是我掰弯的 2024-10-03 10:04:38

显然,对于您浏览的任何网站来说,能够从本地文件系统读取数据都是一个坏主意。所以直接不允许。

也许解决这个问题的最佳方法是使用 FileOpenService。这为应用程序提供了一个简单的界面,可以连接某种描述的文件选择器,可以打开(读取,不幸的是,写入)用户选择的文件,而无需直接访问文件系统。

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. 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.

迟到的我 2024-10-03 10:04:38

一种可能是,您的 jar 没有按照此处所述进行签名

One possibility is, your jar is not signed as mentioned here

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