HOWTO: RMI without rmiregistry
843793Feb 6 2004 — edited Sep 23 2008I'm putting this here for future common reference.
Usually you go start rmiregistry in the background, get your app to register with the registry and everything is fine. Internally RMI keeps an index of the objects being exported. It associates the index with a name inside an RMI registry. Without the registry you can export an object but noone knows what the index is so you're screwed.
This means that you've got to deploy rmiregistry and your application. What you want to do for smallish/simple applications is install both rmiregistry and your remote objects on the same port internal to your app.
Lets say we want our application on port 2004.
Registry localreg = LocateRegistry.createRegistry(2004);
MyService svc = new MyService(2004);
localreg.bind("FlikFlak",svc);
public class MyService extends UnicastRemoteObject
{
public MyService(int port)
{
super(port);
}
}
And thats it. One port with an internally bound rmiregistry. Other applications would continue as normal using that port for both your application and that object.
eg:
MyService svc = (MyService)Naming.lookup("//machine:2004/FlikFlak");