tags:

views:

17

answers:

1

I'm missing something about the difference between

  1. starting rmiregistry at the command prompt (separately from whatever Java process is running a server that implements an RMI interface)
  2. having the server call LocateRegistry.getRegistry()
  3. having the server call LocateRegistry.createRegistry(Registry.REGISTRY_PORT)

I just want my server to register its exported objects with the registry, creating one if there isn't one running already. What's the best way to do this?

A: 

This is how I used to do it, not sure if it is the right way though :/. I also had to mess around with policy files, so if this gives you trouble as well (the security manager part) you must create a policy file and use it.

    try
            {
                try
                {
                    java.rmi.registry.LocateRegistry.createRegistry(1099);
                }

               catch (java.rmi.server.ExportException e) {  /*  */  }

                System.setSecurityManager(new java.rmi.RMISecurityManager());
                Registry registry = LocateRegistry.getRegistry("127.0.0.1",1099);
                registry.rebind(...);
            }

            catch (Exception e) {   /*  */  }
    }
npinti