我是java的RMI主题的新手,我想使用RMI创建客户端服务器应用程序,
我按照此链接中的教程:RMI Tutorial using eclipse
但我使用 netbeans ,这是服务器代码:
import java.rmi.*;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.*;
public class AdditionServer {
public static void main (String[] argv) {
try {
if (System.getSecurityManager() == null)
{
System.setSecurityManager(new SecurityManager());
}
String policy="file:/home/user/NetBeansProjects/RMIServerSide/security.policy";
System.setProperty("java.security.policy",policy);
Addition Hello = new Addition();
System.out.println("test\n");
Registry reg=LocateRegistry.createRegistry(1099);
reg.rebind("rmi://localhost/ABC", Hello);
System.out.println("Addition Server is ready.");
}catch (Exception e) {
System.out.println("Addition Server failed: " + e);
}
}
}
和security.policy:
grant codeBase "/home/user/NetBeansProjects/RMIServerSide/build/classes/" {
permission java.security.AllPermission;
};
然后我运行rmiregistry&在终端。 然后我运行服务器,这里的确切输出是什么:
Addition Server failed: java.security.AccessControlException: access denied ("java.util.PropertyPermission" "java.security.policy" "write")
有没有我想念的东西,比如vm的配置或什么的东西??? .....
答案 0 :(得分:0)
您需要在安装SecurityManager.
之前设置策略文件
答案 1 :(得分:0)
我遇到了同样的问题。我按照以下步骤修复了它:
security.policy
包含以下内容
grant {
// Allow everything for now
permission java.security.AllPermission;
};
2-在将远程对象绑定到rmiregistry
之前添加以下代码行。
System.setProperty("java.security.policy","file:./security.policy");