[英]java.security.AccessControlException: access denied in Java RMI Telephone Directory
I got this source over the internet for my academic assignment purpose. 我出于学术目的通过互联网获得了此资源。 Its just a practical of Java RMI.
它只是Java RMI的实用工具。 Here i am posting the code of my server file.
我在这里发布服务器文件的代码。
import java.io.*;
import java.util.*;
import java.rmi.*;
import java.rmi.server.*;
public class LookupServer extends UnicastRemoteObject implements Lookup {
private Vector save = new Vector();
public LookupServer(String db) throws RemoteException
{
try {
FileReader fr = new FileReader(db);
BufferedReader br = new BufferedReader(fr);
String s = null;
while ((s = br.readLine()) != null)
save.addElement(s);
fr.close();
}
catch (Throwable e) {
System.err.println("Exception in Lookupserver():"+e);
System.exit(1);
}
}
public String findInfo(String info)
{
if (info == null)
return null;
info = info.toLowerCase();
int n = save.size();
for (int i = 0; i < n; i++) {
String dbs = (String)save.elementAt(i);
if (dbs.toLowerCase().indexOf(info) != -1)
return dbs;
}
return null;
}
public static void main(String args[])
{
try {
RMISecurityManager security = new RMISecurityManager();
System.setSecurityManager(security);
String db = args[0];
LookupServer server = new LookupServer(db);
Naming.rebind("LookupServer", server);
System.err.println("LookupServer ready...");
}
catch (Throwable e) {
System.err.println("Exception in main: " + e);
System.exit(1);
}
}
}
My Policy file (policy.policy) includes 我的政策文件(policy.policy)包括
grant
{
// Allow everything for now
permission java.security.AllPermission;
};
Now i am stuck at : 现在我被困在:
C:/>java LookupServer Database.txt java.security.policy=policy.policy C:/> java LookupServer Database.txt java.security.policy = policy.policy
Exception in main: java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve) main中的异常:java.security.AccessControlException:访问被拒绝(java.net.SocketPermission 127.0.0.1:1099 connect,resolve)
Please Help me...! 请帮我...!
应使用-D
而不是参数将策略文件作为属性传递
C:/>java -Djava.security.policy=policy.policy LookupServer Database.txt
Thanks Dear 亲爱的,谢谢
Actually i have gone through several ppts and pdfs of RMI and I get to knew about running and compiling the programs. 实际上,我已经阅读了RMI的ppts和pdf文件,并且了解了运行和编译程序的知识。 Almost all documents was suggesting me to pass -D as a properties not as parameter.
几乎所有文档都建议我将-D作为属性而不是参数。 but when i did, it was giving me an error message of access exception.
但是当我这样做时,它给了我访问异常的错误消息。 Then i have placed my policy file in my C drive and used the command
然后,我将策略文件放置在C驱动器中,并使用了以下命令
C:/>java -Djava.security.policy=C:/policy.policy LookupServer Database.txt C:/> java -Djava.security.policy = C:/policy.policy LookupServer Database.txt
And It worked... :) My RMI applications is running successfully. 而且工作正常... :)我的RMI应用程序正在成功运行。 Thanks for your response.
感谢您的答复。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.