Java RMI客户端服务器Java.security.AccessControlException:拒绝访问(“Java.util.PropertyPermission”Java.security.policy“write”)

Java RMI客户端服务器Java.security.AccessControlException:拒绝访问(“Java.util.PropertyPermission”Java.security.policy“write”),java,rmi,Java,Rmi,我正在用java制作一个简单的RMI服务器。我想通过网络,所以我不能使用本地主机作为IP地址。我编写了很多代码,但我不断收到一条错误消息,内容如下: java.security.AccessControlException: access denied("java.util.PropertyPermission" "java.security.policy" "write") at java.security.AccessControlContext.checkPermission(

我正在用java制作一个简单的RMI服务器。我想通过网络,所以我不能使用本地主机作为IP地址。我编写了很多代码,但我不断收到一条错误消息,内容如下:

  java.security.AccessControlException: access denied("java.util.PropertyPermission" "java.security.policy" "write")
    at java.security.AccessControlContext.checkPermission(Unknown Source)
        at java.security.AccessController.checkPermission(Unknown Source)
        at java.lang.SecurityManager.checkPermission(Unknown Source)
        at java.lang.System.setProperty(Unknown Source)
at test_Client.TestClient.main(TestClient.java:31)
我做了很多查找,似乎无法找出我的代码有什么问题。我的服务器启动正常,并在我指定的ip和端口号上运行。如果有人能帮我找出我为什么会犯这个错误,那就太好了。谢谢 这是我客户的示例代码

package test_Client;
//this is the client, it has it's own package 

import java.rmi.NotBoundException;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.Scanner;
//import all needed rmi files


import test_Interface.Constant;
import test_Interface.testRMIInterface;
//import my constant file so port number can be found.
//import my test interface from my example interface project, example server testing

public class TestClient {
//start my class


    public static void main(String[] args) throws RemoteException, NotBoundException{
        //throws exceptions so everything is not in try catch blocks...

         if (System.getSecurityManager() == null) {
                System.setSecurityManager(new SecurityManager());
            }



         System.setProperty("java.security.policy", "C:/Users/Robert/workspace/ExampleClient");



         Registry registryClient = LocateRegistry.getRegistry(Constant.SERVER_IP, Constant.PORT_NUM);
        //make my registry client and use port number from constants in example interface
        //get the registry on the servers ip address with the port. 

         testRMIInterface remote =  (testRMIInterface) registryClient.lookup(Constant.RMI_ID);
        //using testInterface interface under my example interface
       //look up the RMI ID and link it to the object created above 




         //this is the one method i have on the server.

         String sendThis = "";
         System.out.println("Please enter a word");
         Scanner keyboard = new Scanner(System.in);
         sendThis = keyboard.next();
         System.out.println(remote.returnTest(sendThis));
        //simple call to the server method returnTest 
        //takes in a string. and returns a different one 
    }
}

在安装
SecurityManager之前,需要设置策略属性。


否则,
SecurityManager
将加载默认策略,该策略不会授予您更改策略的权限。

这与您的SecurityManager有关。我不知道确切的答案,但要看的地方是如何设置自定义安全策略(您可以通过命令行作为args进行设置)或使用SecurityManager。在这里查看security.policy以及如何使用它:谢谢,我以前看过这个,但我还没有完全理解它。我仍然在线程“main”java.security.AccessControlException:access denied(“java.net.SocketPermission”“10.0.7.82:5555555”“connect,resolve”)中遇到这个异常java.lang.SecurityManager中的java.security.AccessControlContext.checkPermission(未知源)java.security.AccessController.checkPermission(未知源)java.lang.SecurityManager中的checkPermission(未知源)java.lang.SecurityManager.checkConnect(未知源)java.net.Socket.connect(未知源)位于java.net.Socket。(未知源)位于java.net.Socket。(未知源)位于sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(未知源)位于sun.rmi.transport.tcp.TCPEndpoint.newSocket(未知源)位于sun.rmi.server.UnicastRef.newCall(未知源)的sun.rmi.transport.tcp.tcpcchannel.newConnection(未知源)的sun.rmi.transport.tcp.tcpcchannel.createConnection(未知源)位于test_Client.TestClient.main(TestClient.java:38)的sun.rmi.transport.tcp.tcpcchannel.newConnection(未知源)