tags:

views:

254

answers:

1

I'm writing an rmi application. Everything works perfectly fine when i put the all classes in one directory(one single package). However, when i try to split the server part and the client part, exceptions happens to the client. Server works normally. Here is part of the stack trace of after exception happens:

Exception in thread "main" 
    java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
        java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
        java.lang.ClassNotFoundException: com.clientpackage.ClientImpl_Stub (no security manager: RMI class loader disabled)

I used unicastRemoteobject method to pass the server an instance of an object from client for the callback. I also use rmic to generate the stub file for the object. It seems that the the program can't find that stub class on its CLASSPATH. I'm wondering how to I solve this problem?

+3  A: 

The problem is that you are using rmic. Unless you are using a version of Java strictly prior to Java 5, this is not recommended.

Java 5 and later version will generate a stub dynamically. Using rmic is only necessary if you have to support Java 1.4 or older clients.

In Java 5 and later, if the stubs are generated with rmic, and are present on the server's class path, the client will try to load them through the RMI class loader, even if they are already available on the client's class path.

Also, if you don't intend to use the RMI class loader, there's no need to set the server codebase.

erickson
+1 because you obviously have seen this problem before :)
aperkins
Unfortunately, yes!
erickson
Exception in thread "main" java.rmi.StubNotFoundException: Stub class not found...I got rid of the stub file generated by rmic. It now throws the excepions show above. Do you have an idea why is this?
CKeven
1) Are you running Java 5 or later? 2) Did you restart the RMI registry? 3) Did you clean up *all* artifacts produced by `rmic`?
erickson