MAHAMAD QADIR
MAHAMAD QADIR

Reputation: 1

Using RMI on the windows 7

I am a new with using RMI on windows 7, and I want to run my project with RMI to show "HelloWorld", but I could not run it, because I have got the following error. anyone can help me please. also I have used JDK 1.6.

My error is:

java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:

    java.lang.ClassNotFoundException: Hello_Stub

Upvotes: 0

Views: 1964

Answers (3)

user207421
user207421

Reputation: 310916

There are three ways you can get this exception:

  1. When constructing/exporting your remote object. In this case it means you haven't supplied a port number parameter to super(int port...) if your remote object extends UnicastRemoteObject, or to UnicastRemoteObject.exportObject() otherwise, and you haven't generated a stub via rmic. Note that if you supply a port number parameter, even zero, you don't need to run rmic at all.

  2. When binding/rebinding the remote object to the Registry (in the server). In this case it means you haven't supplied a port number etc as above, but you have generated the stub, otherwise you wouldn't get this far because of (1), but the _Stub class isn't available to the Registry on its CLASSPATH. The simplest solution to this is to run the Registry in the same JVM, via LocateRegistry.createRegistry(). Note that the return value of this method needs to be stored somewhere where it won't be garbage-collected, e.g. in a static variable.

  3. When looking up the Registry (in the client). In this case it means you haven't supplied a port number etc as above, but you have generated the stub, otherwise you wouldn't get this far because of (1) and (2), but the _Stub class isn't available to the client on its CLASSPATH. Solution: deploy it to the client.

Upvotes: 1

Chris Dennett
Chris Dennett

Reputation: 22721

It sounds like maybe you're perhaps following an outdated version of this tutorial: http://docs.oracle.com/javase/1.5.0/docs/guide/rmi/hello/hello-world.html. If that's not the case, check your Java version on the command line (java -version).

Upvotes: 0

Edwin Dalorzo
Edwin Dalorzo

Reputation: 78589

I guess you have to use the rmic.exe to generate your remote classes stubs. These are not automatically generated by your Java compiler (javac.exe).

You can define an Ant Task (called rmic) to simplify your life and make sure your stubs are automatically generated.

If you are using Eclipse you can even include this task as part of your building process so that you can be sure they are generated every time your code is compiled. Most probably other IDEs offer similar features.

Upvotes: 0

Related Questions