我正在尝试编写一个小型 Java 小程序来读取用户浏览历史记录。因此,我需要做的就是读取用户本地文件系统上的文件。
不过我还没有成功。当我尝试使用 JNLP API 的 ExtendedService openFile() 时,getInputStream() 失败并出现 IOException。我尝试使用 FileOpenService openFileDialog(),但是当对话框打开时,目录显示为空或带有不可访问的图标。
屏幕截图在这里: http: //timewitnesser.com/publisher/screenshot1.png和这里http://timewitnesser.com/publisher/screenshot2.png
关于我如何构建和部署它的一些细节:我基本上遵循 Java 小程序的部署指南:docs.oracle.com/javase/tutorial/deployment/applet/deployingApplet.html
我使用 jnlp 文件来启动小程序。我尝试将安全设置为所有权限或未指定。这是 jnlp 文件的代码:
<?xml version="1.0" encoding="UTF-8"?> <jnlp spec="1.0+" codebase="" href=""> <information> <title>History Reader</title> <vendor>QualityWeb</vendor> </information> <resources> <j2se version="1.7+" href="http://java.sun.com/products/autodl/j2se" /> <jar href="HistoryReaderApplet.jar" main="true" /> </resources> <security> <all-permissions/> </security> <applet-desc name="History Reader Applet" main-class="historyreaderapplet.HistoryReaderApplet" width="300" height="300"> </applet-desc> <update check="background"/> </jnlp>
在我的 html 页面中,我使用以下代码启动它:
<script src="https://www.java.com/js/deployJava.js"></script> <script> var attributes = { code:'historyreaderapplet.HistoryReaderApplet', width:300, height:300} ; var parameters = {jnlp_href: 'historyreader_applet.jnlp'} ; deployJava.runApplet(attributes, parameters, '1.7'); </script>
我使用 jar 命令构建 jar,包括一个清单,其中我指定了 java 指南中提到的 3 行,包括“Permission one”。我使用的命令是
jar cvfm HistoryReaderApplet.jar mymanifest.txt historyreaderapplet
- 我使用 jarsigner 对 jar 进行签名,虽然我自己使用 keytool 生成了我的密钥,但我没有证书颁发机构签署的证书
- 我什至尝试将我的本地 java 机器安全设置设置为中等,并将我的域添加到受信任域列表中。
- 我已经尝试从本地服务器运行页面,并上传到远程服务器
- 当我运行该页面时,它会提示一个授权框,我在其中允许该应用程序。当我在沙盒模式下运行时,当它到达 fileopendialog 时,它再次提示我是否要授权应用程序在本地文件系统上读写,我这样做了。但即使有所有这些确认,它也不起作用。
知道可能是什么问题吗?
编辑:这是 Janela 的报告,我只包括了红色部分:
cvc-complex-type.2.4.a: Invalid content was found starting with element 'security'. One of '{resources, application-desc, applet-desc, component-desc, installer-desc}' is expected.
cvc-complex-type.2.4.a: Invalid content was found starting with element 'security'. One of '{resources, application-desc, applet-desc, component-desc, installer-desc}' is expected.
Codebase '' is a malformed URL! Defaulting to http://timewitnesser.com/publisher/historyreader_applet.jnlp
Codebase '' is a malformed URL! Defaulting to http://timewitnesser.com/publisher/historyreader_applet.jnlp
Codebase '' is a malformed URL! Defaulting to http://timewitnesser.com/publisher/historyreader_applet.jnlp
Codebase '' is a malformed URL! Defaulting to http://timewitnesser.com/publisher/historyreader_applet.jnlp
在我看来,第一行可能是原因,但我不明白。“安全”标签不应该是 jnlp 标签的直接子代吗?