Java RMI(Java Remote Method Invocation) is a Java API that performs the object-oriented equivalent of remote procedure calls (RPC), it allows an object running in one Java virtual machine to invoke methods on an object running in another Java virtual machine. It provides for remote communication where all participating applications are written by Java.

Today, when I ran a “hello world” example, unfortunately I got the following error messages:

Exception in thread "main" java.rmi.MarshalException: error marshalling arguments; nested exception is:
java.io.NotSerializableException: server.Hello
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at java.rmi.Naming.rebind(Naming.java:160)
at server.HelloServer.main(HelloServer.java:24)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:592)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
Caused by: java.io.NotSerializableException: server.Hello
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1081)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:302)
... 8 more

The Java RMI server ran on IDEA9.0 and the Java version is “1.6.0_18″. I confused a lot why this error occurs, my initial understanding was, perhaps, caused by that the JVM engine is not able to detect where are the serialized class or data, but quickly I learned that a required class was missing in classpath.

A Java class can be turned to be remotely accessible by implementing a custom remote interface, it have to extend uka.karmi.rmi.Remote and UnicastRemoteObject. UnicastRemoteObject both, UnicastRemoteObject is exported in constructor, but my remote object has not implemented class UnicastRemoteObject. I extended UnicastRemoteObject for calss Hello then “java rmi error unmarshalling arguments” error was gone.
This is code what the error unmarshalling arguments occurs:

public class Hello implements HelloInterface {
  public Hello() throws RemoteException {
  }

  public String sayHello() throws RemoteException {
    return "good hello";
  }
}

I fixed code as below to resolve error unmarshalling arguments:

public class Hello extends UnicastRemoteObject implements HelloInterface {
  public Hello() throws RemoteException {
  }

  public String sayHello() throws RemoteException {
    return "good hello";
  }

}