.java.policy 文件和本地小程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6099661/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
.java.policy file and local applet
提问by rugcutter
I am working on an HTML page that is using Javascript to interact with a Java applet. The HTML page, javascript files, and .jar file for the applet will be deployed locally to a folder on the user's filesystem.
我正在处理使用 Javascript 与 Java 小程序交互的 HTML 页面。小程序的 HTML 页面、javascript 文件和 .jar 文件将在本地部署到用户文件系统上的文件夹中。
(Implmenting this as a standalone Java application is not an option here; for various reasons I will not explain here).
(将它实现为一个独立的 Java 应用程序在这里不是一个选项;出于各种原因,我不会在这里解释)。
The applet needs to do local file i/o. As such, I'm attempting to tweek the settings in the user's .java.policy file to permit this.
小程序需要做本地文件 i/o。因此,我试图调整用户的 .java.policy 文件中的设置以允许这样做。
I have found the following setup is the only one that works:
我发现以下设置是唯一有效的设置:
grant
{
permission java.io.FilePermission "<<ALL FILES>>", "read";
permission java.io.FilePermission "<<ALL FILES>>", "write";
};
This is not ideal, as that it grants all applets permissions to read write all files. Naturally I would prefer to isolate to the particular code base. However I could not find a "grant codeBase" syntax that works.
这并不理想,因为它授予所有小程序读写所有文件的权限。当然,我更愿意隔离到特定的代码库。但是我找不到有效的“grant codeBase”语法。
I have tried:
我努力了:
grant codeBase "file:/C:/Files/FileIOApplet/-" {
permission java.io.FilePermission "<<ALL FILES>>", "read";
permission java.io.FilePermission "<<ALL FILES>>", "write";
};
grant codeBase "file:///-" {
permission java.io.FilePermission "<<ALL FILES>>", "read";
permission java.io.FilePermission "<<ALL FILES>>", "write";
};
grant codeBase "file:${user.home}/-"
{
permission java.io.FilePermission "<<ALL FILES>>", "read";
permission java.io.FilePermission "<<ALL FILES>>", "write";
};
This is running using this configuration:
这是使用此配置运行:
- Firefox 3.6.10
- Java 1.6 update 25
- Windows 7 64 bit
- 火狐 3.6.10
- Java 1.6 更新 25
- 视窗 7 64 位
Where I am I going wrong in setting up this .java.policy file?
在设置这个 .java.policy 文件时我哪里出错了?
I am pretty rusty to the Java world, especially working with applets - so your expertise is appreciated!
我对 Java 世界非常生疏,尤其是使用小程序 - 因此感谢您的专业知识!
回答by SATHISH J
To connect an Applet with access here are the policy tool settings:
要连接具有访问权限的 Applet,请使用策略工具设置:
Go to policyTool, you will find it in following path:
转到 policyTool,您将在以下路径中找到它:
java->jdk1.3->bin->policyTool Application
There appears Policy Tool window.
In the Policy Tool window select the "Add Policy Entry" button.
This will take you to Policy Entry window
出现策略工具窗口。
在“策略工具”窗口中,选择“添加策略条目”按钮。这将带您进入 Policy Entry 窗口
There enter the CodeBase as "file:/path of your java bin". For example
将代码库输入为“文件:/java bin 的路径”。例如
CodeBase file:/c:/java/jdk1.3/bin/
Now press "Add Permission" button in the Policy Entry window.
This will take you to the "Permissions" window
现在按“策略条目”窗口中的“添加权限”按钮。
这将带您进入“权限”窗口
There Select "All permission" from permission drop down list box.
And click "ok".
从权限下拉列表框中选择“所有权限”。
然后点击“确定”。
Now again press the "Add Permission" button in the Policy Entry window.
现在再次按下“策略条目”窗口中的“添加权限”按钮。
Now Select "Select "RunTimepermission" from permission drop down list box.
Now in the Target Name drop down list box select "accessClassInpackage", in the text box enter accessClassInpackage.sun.jdbc.odbc
现在从权限下拉列表框中选择“选择“RunTimepermission”。现在在目标名称下拉列表框中选择“accessClassInpackage”,在文本框中输入 accessClassInpackage.sun.jdbc.odbc
Now click "ok".
现在点击“确定”。
Now click "done" in "Policy Entry" window.
现在单击“策略条目”窗口中的“完成”。
Now in the Policy Entry window file->save Save it in "bin" of your Java installation. Remember the name... for example say.. appletpermission 'save'
现在在 Policy Entry 窗口中的 file->save 将其保存在 Java 安装的“bin”中。记住名字...例如说... appletpermission 'save'
Now you have a created policy file for access
现在您已经创建了一个用于访问的策略文件
Now to compile your java file at the command prompt
现在在命令提示符下编译你的 java 文件
javac programname.java
To run your program type the following at the cmd prompt:
要运行您的程序,请在 cmd 提示符下键入以下内容:
appletviewer -J-Djava.security.policy=appletpermission programname.java
Now everything is done.
现在一切都完成了。
回答by EricParis16
don't waste your time with syntax, use the policy tool instead :
不要在语法上浪费时间,而是使用策略工具: