views:

112

answers:

2

I'm writing an rmi application. Everything works perfectly fine when i put the all classes in one directory. However, when i try to split the server part and the client part, it raises java.lang.ClassNotFoundException.myclasses It seems to be the Registry can't find that class on its CLASSPATH. I'm wondering how to I solve this problem?

A: 

The registry is there to link up client interfaces with their server implementation classes. On the client, you will need to have the interface class definitions on the classpath.

Also, the client should not reference the implementation class at all - everything should be in the interface/stub class.

If this does not answer your question, you'll need to be more specific and provide at least some code.

Stephen
A: 

Are you specifying the classpath directories in the arguments to both the client and server?

From the Tutorial:

Server

On the Solaris Operating System:

java -classpath classDir -Djava.rmi.server.codebase=file:classDir/ example.hello.Server &

On Windows platforms:

start java -classpath classDir -Djava.rmi.server.codebase=file:classDir/ example.hello.Server

Once the server is ready, the client can be run as follows:

java -classpath classDir example.hello.Client where classDir is the root directory of the class file tree

http://java.sun.com/javase/6/docs/technotes/guides/rmi/hello/hello-world.html#5

UberAlex
it solves the problem. However, I have a similar problem when running client. 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.v3q6.ClientBootstrap.ClientImpl_Stub (no security manager: RMI class loader disabled) at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:353)... ...The reason is probably that I used " UnicastRemoteObject.exportObject(client);" Do you have any idea about this?
CKeven
You probably need to run rmic again to generate the stubs.
UberAlex