RMI - Naming:lookup & rebind conflict

2003-09-14 04:13:49 PM
I have problem that rebind fails after calling lookup. Why, and what to do
in the between to prevent this from happening. More deails follows.
RMI server needs to know if there is an instance already running. If not it
continues witn binding. Here is how I do it.
try {
IIMServer oldServer =
if (oldServer.ping()) {
System.out.println("Server already running. Bye.");
} catch (Exception e) {
System.out.println("no old server.");
This above part works fine. However the following does fail and the flow
turns into
the exception and finally exits with -1.
System.setSecurityManager(new RMISecurityManager());
URL url = ClassLoader.getSystemResource("classes"); // app's root dir
must be in classpath !!
System.setProperty("java.rmi.server.codebase", url.toString()+"/");
try {
} catch (Exception e) {
System.exit( -1);
System.out.println("Server created.");
It is fascinating that if I remove first part of code (which seeks for old
instance of server)
the second part works perfectly. (btw: policy and codebase are set nicely
and properly).
Why does that happen ? I am astonished. If anyone had this problem please
let me know the solution.
Kindest regards