Error registering an RMI service

1

I have the following class which represents 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 was able to generate HelloImpl_Stub.class , but when I try to register:

rmiregistry -Java HelloImpl

The following error occurs:

  

Error: Could not find or load the 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)
    
asked by anonymous 19.02.2016 / 17:41

0 answers