0

I am trying to run the example given in the official Oracle website of a RMI application.Here is my oldest post where I explain the previous problems I had Running a sample RMI application.

However, I still have this problem :

ComputeEngine exception:
  java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
java.lang.ClassNotFoundException: compute.Compute
at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:419)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:267)
at sun.rmi.transport.Transport$1.run(Transport.java:177)
at sun.rmi.transport.Transport$1.run(Transport.java:174)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:556)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:811)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:670)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:275)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:252)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:378)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at engine.ComputeEngine.main(ComputeEngine.java:30)
Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
java.lang.ClassNotFoundException: compute.Compute
at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:409)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:267)
at sun.rmi.transport.Transport$1.run(Transport.java:177)
at sun.rmi.transport.Transport$1.run(Transport.java:174)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:556)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:811)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:670)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
Caused by: java.lang.ClassNotFoundException: compute.Compute
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.rmi.server.LoaderHandler$Loader.loadClass(LoaderHandler.java:1206)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:270)
at sun.rmi.server.LoaderHandler.loadClassForName(LoaderHandler.java:1219)
at sun.rmi.server.LoaderHandler.loadProxyInterfaces(LoaderHandler.java:729)
at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:673)
at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:610)
at java.rmi.server.RMIClassLoader$2.loadProxyClass(RMIClassLoader.java:646)
at java.rmi.server.RMIClassLoader.loadProxyClass(RMIClassLoader.java:311)
at sun.rmi.server.MarshalInputStream.resolveProxyClass(MarshalInputStream.java:255)
at java.io.ObjectInputStream.readProxyDesc(ObjectInputStream.java:1556)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1512)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1769)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1348)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370)
... 13 more

This is the content of the ComuteEngine.java (server):

package engine;

import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import compute.Compute;
import compute.Task;

public class ComputeEngine implements Compute {

public ComputeEngine() {
    super();
}

public <T> T executeTask(Task<T> t) {
    return t.execute();
}

public static void main(String[] args) {
    if (System.getSecurityManager() == null) {
        System.setSecurityManager(new SecurityManager());
    }
    try {
        String name = "Compute";
        Compute engine = new ComputeEngine();
        Compute stub =
            (Compute) UnicastRemoteObject.exportObject(engine, 0);
        Registry registry = LocateRegistry.getRegistry();
        registry.rebind(name, stub);
        System.out.println("ComputeEngine bound");
    } catch (Exception e) {
        System.err.println("ComputeEngine exception:");
        e.printStackTrace();
    }
}
}

Does anyone know how to resolve that issue ?

Community
  • 1
  • 1
Othmane
  • 1,094
  • 2
  • 17
  • 33
  • Something happens inside `ComputerEngine` in its `main()` method. What is on line # **30** of *ComputeEngine.java* file? – PM 77-1 Sep 29 '14 at 01:12
  • It's : registry.rebind(name, stub); You can have a look at my updated question – Othmane Sep 29 '14 at 01:29
  • See if you Java version is among described in this [Oracle document](http://docs.oracle.com/javase/7/docs/technotes/guides/rmi/enhancements-7.html). – PM 77-1 Sep 29 '14 at 01:38
  • Possibly related post: [Java RMI cannot bind server](http://stackoverflow.com/questions/8157250/java-rmi-cannot-bind-server). I *borrowed* the link from [this answer](http://stackoverflow.com/a/16679337/2055998). – PM 77-1 Sep 29 '14 at 01:41
  • I already tried what they said but in vain – Othmane Sep 29 '14 at 02:16
  • possible duplicate of [java.rmi.ServerException: RemoteException occurred in server thread](http://stackoverflow.com/questions/9531158/java-rmi-serverexception-remoteexception-occurred-in-server-thread) – user207421 Sep 30 '14 at 00:21
  • well, in fact I launch rmiregistry from terminal in the bin directory becuse I heard about such problem then when I try to launch the server from Eclipse it launches the error aforementioned – Othmane Oct 01 '14 at 00:58

1 Answers1

0

I succeded to launch my program by adding :

LocateRegistry.createRegistry(1099);

before creating the security manager.However, launching simply the rmiregistry from my terminal didn't work. I think because of a communcation problem between the server and the rmiregistry, maybe because I have to add some classes to the classpath but I don't know how to do that properly.

user207421
  • 305,947
  • 44
  • 307
  • 483
Othmane
  • 1,094
  • 2
  • 17
  • 33
  • Eh? There are three distinct methods in [my answer](http://stackoverflow.com/a/9542464/207421) in the 'possible duplicate' link. – user207421 Oct 01 '14 at 01:51
  • I have tried earlier to use the codebase feature which didn't work. However, to start the Registry with a CLASSPATH that includes the relevant JARs or directories, I don't know how to do this in terminal cause I think I have already tried it by adding the jar that contained both the Compute AND TASK INTERFACES BUT IT DIDN'T WORK neither with Eclipse nor in terminal – Othmane Oct 01 '14 at 03:51