3

I am trying lo learn RMI by following the Oracle documentation for RMI

I have created the classes for server side and client side, the class details are as follows:

compute.Compute -- Remote interface
compute.Task -- Normal interface
engine.ComputeEngine -- Class that implements remote interface

The code details can be seem from the document at these links:

http://docs.oracle.com/javase/tutorial/rmi/designing.html http://docs.oracle.com/javase/tutorial/rmi/implementing.html

I have followed the steps given in below link to compile the code, all I am doing these are on my machine which has Ubuntu OS.

http://docs.oracle.com/javase/tutorial/rmi/compiling.html

Now as per below link I have placed the policy files for client and server at path : /home/user/public_html

http://docs.oracle.com/javase/tutorial/rmi/running.html

one more difference is I have tomcat server so I placed the class files under Tomcat webapps and under my web application, so I am running the class using the command:

java -cp /home/user/src:. -Djava.rmi.server.codebase=http://myipaddress:8080/myapp/classes/compute.jar -Djava.rmi.server.hostname=myipaddress -Djava.security.policy=server.policy engine.ComputeEngine

Now when I run this application I am getting exception as:

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:745)
    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:31)
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:745)
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:425)
    at sun.rmi.server.LoaderHandler$Loader.loadClass(LoaderHandler.java:1206)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    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:1558)
    at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1e exce514)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370)
    ... 13 more

The exception says java.lang.ClassNotFoundException: compute.Compute. But I have the class file in compute.jar that is located at my path /home/user/src and also I can download it using URL at http://myipaddress:8080/myapp/classes/compute.jar

Also FYI, I am doing all the steps on my machine only without any separate client and server machines.

Can someone please help me how can I fix this issue? Please let me know if you need any further details so I can provide them.

Update:

I followed the asnwer given by @EJP at this post - Is it necessary/important to set a classpath in the RMI registry?

then I started rmiregistry from directory where I have the jar file that has Compute.class and then ran the below command:

java -cp /home/user/src:/home/user/public_html/classes/compute.jar -Djava.rmi.server.codebase=http://myipaddress:8080/myapp/classes/compute.jar -Djava.rmi.server.hostname=myipaddress -Djava.security.policy=server.policy engine.ComputeEngine

But still I am getting same exception.

Community
  • 1
  • 1
learner
  • 6,062
  • 14
  • 79
  • 139
  • My answer in the duplicated question doesn't say anything about starting the Registry in a directory containing a JAR file. It does however give the only three other working solutions I'm aware of. See also [here](http://stackoverflow.com/a/23643744/207421). – user207421 Dec 05 '14 at 22:47

1 Answers1

-1

That class isn't on the Registry's CLASSPATH.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • 1
    As per the document it is not mentioned anywhere. Can you please tell me how can place it the registry classpath? – learner Dec 05 '14 at 18:05
  • I have followed one of your answer in another post but I am getting same error, please check my updated post for details. i – learner Dec 05 '14 at 18:27
  • Why does it need to be mentioned anywhere? The Registry is a Java program, it runs in a JVM, it has a classpath, it throws `ClassNotFundExceptions` just like any other Java code. – user207421 Dec 05 '14 at 22:42
  • 1
    ,Thanks for responding, I am new to RMI concepts so may be I am asking trivial questions, sorry for that. But I really need help in fixing this. As per the link here -- http://docs.oracle.com/javase/tutorial/rmi/running.html, it says I have to start the `rmiregistry` from command propmt. Also it says `you will run rmiregistry either has no CLASSPATH environment variable set or has a CLASSPATH environment variable that does not include the path to any classes that you want downloaded to clients of your remote objects.` Can you please tell me how should I start the registry to fix this issue – learner Dec 06 '14 at 01:08