Domanda

I'm trying to set up an RMI application that once worked but I'm now getting weird behaviour. When I run it without a Stub I get java.lang.ClassNotFoundException: HelloInterface Then I ADD a new file (Hello_Stub) to the directory (by using rmic), and then I get java.lang.ClassNotFoundException: Hello_Stub

WTF?? It was not complaining about Hello_Stub missing when it was missing; but when I add that file, it starts complaining that it's NOT there. HUH?

What's below is a transcript from the terminal. First you see one error; then I list the files in the current directory; then I generate the Stub file and show you that; then you see the error where it complains that the file just added is missing:

sjudd@kearnsgroup:/kearnsgroup/www/RMItest/classes> java HelloServer
initializing Hello class: Hello, world!
Hello Server failed: java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
    java.lang.ClassNotFoundException: HelloInterface


sjudd@kearnsgroup:/kearnsgroup/www/RMItest/classes> ll
total 32
-rw------- 1 sjudd sjudd 765 Oct 25 19:52 Hello.class
-rw------- 1 sjudd sjudd 967 Oct 25 19:52 HelloClient.class
-rw-r----- 1 sjudd sjudd 614 Oct 25 19:42 HelloClient.java
-rw------- 1 sjudd sjudd 222 Oct 25 19:52 HelloInterface.class
-rw-r----- 1 sjudd sjudd 360 Oct 25 09:08 HelloInterface.java
-rw-r----- 1 sjudd sjudd 847 Oct 25 09:56 Hello.java
-rw------- 1 sjudd sjudd 916 Oct 25 19:52 HelloServer.class
-rw-r----- 1 sjudd sjudd 439 Oct 25 09:14 HelloServer.java


sjudd@kearnsgroup:/kearnsgroup/www/RMItest/classes> rmic Hello
sjudd@kearnsgroup:/kearnsgroup/www/RMItest/classes> ll
total 36
-rw------- 1 sjudd sjudd  765 Oct 25 19:52 Hello.class
-rw------- 1 sjudd sjudd  967 Oct 25 19:52 HelloClient.class
-rw-r----- 1 sjudd sjudd  614 Oct 25 19:42 HelloClient.java
-rw------- 1 sjudd sjudd  222 Oct 25 19:52 HelloInterface.class
-rw-r----- 1 sjudd sjudd  360 Oct 25 09:08 HelloInterface.java
-rw-r----- 1 sjudd sjudd  847 Oct 25 09:56 Hello.java
-rw------- 1 sjudd sjudd  916 Oct 25 19:52 HelloServer.class
-rw-r----- 1 sjudd sjudd  439 Oct 25 09:14 HelloServer.java
-rw------- 1 sjudd sjudd 1635 Oct 25 20:34 Hello_Stub.class


sjudd@kearnsgroup:/kearnsgroup/www/RMItest/classes> java HelloServer
initializing Hello class: Hello, world!
Hello Server failed: java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
    java.lang.ClassNotFoundException: Hello_Stub

Note that what is failing here is the rmi SERVER, not the client.

This code runs fine on one machine (a Mac), but when copied to another (Linux), it throws this astonishing error.

I am so blown away by this weirdness I don't know how to approach it. Might this have anything to do with the unmarshalling step? or with environment variables? CLASSPATH perhaps? I can't see what to look for. Any wild theories?

È stato utile?

Soluzione

Don't add the stub. You haven't needed one since Java 1.5. Just make sure you follow the requirements outlined in the preamble to the Javadoc for UnicastRemoteObject. The original problem is caused by the remote interface class not being available on the CLASSPATH to the Registry or the client, or both.

Altri suggerimenti

I had started rmiregistry without paying any attention to its class path. By cd'ing to the classes directory and starting it there, all problems went away.

I believe you can accomplish the same thing with flags that specify the CLASSPATH or the codebase for the rmiregistry program. Does anyone know the syntax? I have tried these (unsuccessfully):

rmiregistry -JCLASSPATH="path/to/classes/"
rmiregistry -JCLASSPATH="/absolute/path/to/classes/"
rmiregistry -J-DCLASSPATH="path/to/classes/"
rmiregistry -J-DCLASSPATH="/absolute/path/to/classes/"

They all cause a java.lang.ClassNotFoundException: BNS.plumbing.SessionHostInterface when the server starts running. (This is new behaviour, at least.)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top