public class BizImpl extends UnicastRemoteObject implements Biz {
private static final long serialVersionUID = -8559392326593037120L;
public BizImpl() throws RemoteException {
super();
}
@Override
public String aloha() throws RemoteException {
return "Aloha Baby.";
}
}
public class Server {
public Server() {
try {
Biz bis = new BizImpl();
// style-1
Registry registry = LocateRegistry.createRegistry(RMIParameter.PORT);
registry.rebind(RMIParameter.NAME, bis); // replace existing binding name
// style-2
//java.rmi.Naming.rebind(RMIParameter.NAME, bis); // replace existing binding name
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String args[]) {
new Server();
}
}
style-2 須要指定一個Policy文件或者運行rmiregistry
java -Djava.security.policy=folder_x/rmi/policy_file creative.fire.rmi.Server
Policy文件的內容爲:
grant{
permission java.net.SocketPermission "localhost:9527", "connect, resolve";
};
運行rmiregistry是修改 JDK 目錄下的jre/lib/security/java.policy
rmiregistry(linux)
start rmiregistry(windows)
容許任何人(targets)做任何事情(actions):
grant{
permission java.security.AllPermission "","";
};
OR
grant {
permission java.security.AllPermission;
};