2011-01-11 44 views
0

如何對java.security.AccessControlException問題進行排序?當我運行myRMIServer時,我得到這個異常?如何在運行rmi程序時對java.security.AccessControlException問題進行排序?

我的代碼:

import java.rmi.*; 
import java.rmi.server.UnicastRemoteObject; 

public class myRMIServer 
{ 
     public static void main(String[] argv) 
       { 
       System.setSecurityManager(new RMISecurityManager()); 
       try 
         { 
         myRMIImpl implementation = new myRMIImpl("myRMIImplInstance"); 
         } 
       catch (Exception e) 
         { 
         System.out.println("Exception occurred: " + e); 
         } 
       } 
} 

public interface myRMIInterface extends java.rmi.Remote 
{ 
     public java.util.Date getDate() throws java.rmi.RemoteException; 
} 

import java.rmi.*; 
import java.rmi.server.UnicastRemoteObject; 

public class myRMIImpl extends UnicastRemoteObject implements myRMIInterface 
{ 
     public myRMIImpl(String name) throws RemoteException 
       { 
       super(); 
       try 
         { 
         Naming.rebind(name, this); 
         } 
       catch(Exception e) 
         { 
         System.out.println("Exception occurred: " + e); 
         } 
       } 
     public java.util.Date getDate() 
       { 
       return new java.util.Date(); 
       } 
} 

輸出

Exception occurred: java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve) 

我該如何解決這個問題?

回答

1

定義一個授予所需權限的.policy文件,並將其命名爲java.security.policy參數。

或擺脫安全經理。只有在使用RMI代碼庫功能時才需要。