RMI测试程序都没通过,高手帮看一下!
初学RMI,写了如下小程序:
public interface GetTimeI extends Remote {
public abstract long getTime() throws RemoteException;
}
public class GetTimeImpl extends UnicastRemoteObject implements GetTimeI {
private static final long serialVersionUID = 7715100257443541391L;
private String name;
protected GetTimeImpl(String name) throws RemoteException {
super();
this.name = name;
}
public static void main(String[] args) throws Exception {
System.setSecurityManager( new RMISecurityManager());
GetTimeImpl myApp = new GetTimeImpl("GetTime");
System.out.println("rebind........");
Naming.rebind("rmi://127.0.0.1/GetTime", myApp);
System.out.println("Ready!");
}
public long getTime() throws RemoteException{
return System.currentTimeMillis();
}
}
运行时抛出以下异常:
Exception in thread "main" java.security.AccessControlException: access denied (java.net.SocketPermission 192.168.1.100:1099 connect,resolve)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkConnect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown Source)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown Source)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
at sun.rmi.server.UnicastRef.newCall(Unknown Source)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at java.rmi.Naming.rebind(Unknown Source)
at GetTimeImpl.main(GetTimeImpl.java:33)
请问我的程序那里出了问题?