Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

HOWTO: RMI without rmiregistry

843793Feb 6 2004 — edited Sep 23 2008
I'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");
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 21 2008
Added on Feb 6 2004
6 comments
1,118 views