How do I sort the java.security.AccessControlException issue when running rmi programs?
How do I sort the java.security.AccessControlException problem? When I am running the myRMIServer,I am getting this exception?
My c开发者_高级运维odes:
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();
}
}
Output
Exception occurred: java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)
How do I solve this problem?
Define a .policy file that grants the required permissions, and name it in a java.security.policy argument.
Or get rid of the security manager. It's only required if you are using the RMI codebase feature.
精彩评论