Error when registering an RMI Service

Asked

Viewed 61 times

1

I have the following Class representing a service:

public class HelloImpl extends UnicastRemoteObject implements Hello {

    protected HelloImpl() throws RemoteException {
        super();
    }

    @Override
    public String sayHello() throws RemoteException {
        return "Hello in "+new SimpleDateFormat("HH:mm:ss.SSS").format(Calendar.getInstance().getTime());
    }

    public static void main(String[] args) {
        try{
            System.getProperties().put("java.security.policy", "policy.all");
            System.setSecurityManager(new SecurityManager());
            System.setProperty("java.rmi.server.hostname", Inet4Address.getLocalHost().getHostAddress());

            HelloImpl helloImpl = new HelloImpl();
            Naming.rebind("HelloServer", helloImpl);
        }catch(final Exception e){
            System.out.println("erro : "+e.getMessage());
            e.printStackTrace();
        }
    }
}

I managed to generate the HelloImpl_Stub.class, but when I try to register:

rmiregistry -Java HelloImpl

The following error occurs:

Error: Unable to find or load main class Ava

My operating system is Macos.

When I try to run the class the following error occurs :

error init Server : access denied ("java.util.PropertyPermission" "java.rmi.server.hostname" "write")
java.security.AccessControlException: access denied ("java.util.PropertyPermission" "java.rmi.server.hostname" "write")
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:457)
    at java.security.AccessController.checkPermission(AccessController.java:884)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
    at java.lang.System.setProperty(System.java:792)
    at HelloImpl.main(HelloImpl.java:24)
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.