Reputation: 189686
I'm missing something about the difference between
LocateRegistry.getRegistry()
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?
Upvotes: 1
Views: 1360
Reputation: 247
Old thread but...
man rmiregistry
says:
The methods of the java.rmi.registry.LocateRegistry class are used to get a registry operating on the local host or local host and port.
otherwise you have:
The URL-based methods of the java.rmi.Naming class operate on a registry and can be used to look up a remote object on any host and on the local host
So I guess that's the important difference. Other thing is SecurityManager and policies.
Upvotes: 2
Reputation: 52185
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) { /* */ }
}
Upvotes: 1