Oracle says that registry
is
a bootstrap naming service that is used by RMI servers on the same host to bind remote objects to names
Now, I have such a server that uses rmiregistry
for providing JNDI
.
public class ObjectProvider {
public static void main(String[] args) {
System.setProperty("java.rmi.server.codebase", "file:/absolute/path/to/jar/where/person/class/is/my.jar");
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory");
Context context = new InitialContext(env);
context.bind("jordan", new Person("Michael Jordan"));
Person p = (Person) context.lookup("jordan");
System.out.println("jordan = " + p.getName());
}
}
And Person class:
public class Person implements Remote, Serializable {
String name;
public Person(String name) { this.name = name; }
public String getName() { return name; }
}
And rmiregistry
is started as rmiregistry &
. Yet, when I run the code it complains about not being able to unmarshall arguments when performing bind
because the class Person
cannot be found.
I understand that rmiregistry
does not find the class file but I don't understand why. Is this the right way to tell it where it can find the classes to be bound?