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?
2 Answers
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
-
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? – Progress Programmer Sep 27 '09 at 23:38
-
You probably need to run rmic again to generate the stubs. – UberAlex Sep 28 '09 at 08:09
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.

- 19,488
- 10
- 62
- 83
-
No. The Registry is there to link up names with stubs. It doesn't know anything about he implementation classes whatsoever. But to hold an instance of the stub, it needs that class in its CLASSPATH, and every application class that the stub depends on. – user207421 Jul 05 '17 at 03:42