0

So we haft to use a RMI Server and Client for some exercice in class. Our professor don't want us to use `LocateRegirstry.createRegistry()`, instead we shall start the rmiregistry from within either intellij external tools, or the cmd. I tried several things, nothing seems to work. I opened cmd both as Admin and normal User, started rmiregistry from within the "out" dictionary of the project (professor said it has to be started in the same dictionary where the byte code lies). Made a link to the original rmiregistry and placed it into the "out" dictionary,startet it from intellij terminal, external tools etc. but i cant get it to work. at the moment i get this Error:
 DateServerImpl: RemoteException occurred in server thread; nested exception is: 
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
    java.lang.ClassNotFoundException: RMI.DateServer
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
    java.lang.ClassNotFoundException: RMI.DateServer
    at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:391)
    at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
    at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:691)
    at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
    at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:587)
    at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:828)
    at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:705)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:704)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
    at java.base/java.lang.Thread.run(Thread.java:832)
    at java.rmi/sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:303)
    at java.rmi/sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:279)
    at java.rmi/sun.rmi.server.UnicastRef.invoke(UnicastRef.java:380)
    at java.rmi/sun.rmi.registry.RegistryImpl_Stub.rebind(RegistryImpl_Stub.java:158)
    at java.rmi/java.rmi.Naming.rebind(Naming.java:177)
    at RMI.DateServerImpl.main(DateServerImpl.java:20)
Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
    java.lang.ClassNotFoundException: RMI.DateServer
    at java.rmi/sun.rmi.registry.RegistryImpl_Skel.dispatch(RegistryImpl_Skel.java:157)
    at java.rmi/sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:468)
    at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:298)
    at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
    at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:691)
    at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
    at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:587)
    at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:828)
    at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:705)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:704)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
    at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: java.lang.ClassNotFoundException: RMI.DateServer
    at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:435)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
    at java.rmi/sun.rmi.server.LoaderHandler$Loader.loadClass(LoaderHandler.java:1207)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Class.java:468)
    at java.rmi/sun.rmi.server.LoaderHandler.loadClassForName(LoaderHandler.java:1221)
    at java.rmi/sun.rmi.server.LoaderHandler.loadProxyInterfaces(LoaderHandler.java:731)
    at java.rmi/sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:674)
    at java.rmi/sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:611)
    at java.rmi/java.rmi.server.RMIClassLoader$2.loadProxyClass(RMIClassLoader.java:646)
    at java.rmi/java.rmi.server.RMIClassLoader.loadProxyClass(RMIClassLoader.java:311)
    at java.rmi/sun.rmi.server.MarshalInputStream.resolveProxyClass(MarshalInputStream.java:254)
    at java.base/java.io.ObjectInputStream.readProxyDesc(ObjectInputStream.java:1950)
    at java.base/java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1892)
    at java.base/java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2202)
    at java.base/java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1712)
    at java.base/java.io.ObjectInputStream.readObject(ObjectInputStream.java:519)
    at java.base/java.io.ObjectInputStream.readObject(ObjectInputStream.java:477)
    at java.rmi/sun.rmi.registry.RegistryImpl_Skel.dispatch(RegistryImpl_Skel.java:154)
    ... 14 more

I couldn't find the solution on google ( which leads me here anyway most of the time, to similar problems, but couldn't figure anything out with those posts)

here is the code i use:

Server Code

    package RMI;

import java.rmi.*;
import java.rmi.server.*;
import java.util.Date;

public class DateServerImpl extends UnicastRemoteObject implements DateServer {
  public DateServerImpl () throws RemoteException {
  }

  public Date getDate () throws RemoteException {
    System.out.println("Invocation of getDate()");
    return new Date ();
  }

  public static void main (String[] args) {

    try {
      DateServerImpl dateServer = new DateServerImpl ();
      Naming.rebind ("DateServer", dateServer);
      System.out.println("The server is up");
      
    } catch (Exception e) {
        System.out.println("DateServerImpl: " + e.getMessage());
        e.printStackTrace();
    }
  }
}

Interface Code

package RMI;

import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.Date;

public interface DateServer extends Remote {
  public Date getDate () throws RemoteException;
}

So I hope anybody can help me here. What am I doing wrong?
I hope this is enough information, first time posting here =D
Thank you!

  • @Community I know that's an automatic message but it is a futile one. There is quite enough information here for the question to be answered. – user207421 May 12 '22 at 07:04
  • Start the `rmiregistry` from the same place you are running the `java` command from to execute your client and server. It needs the same class path as they do. – user207421 May 12 '22 at 07:04
  • though i did it, jusst tried again with start rmiregistry -J-Djava.class.path=C:\Users\\Documents\Studium\Module\DistriSys\LectureCodes\out\production\LectureCodes\RMI (im on windows) startet the registry in new terminal window, but the error still was the same – user19094445 May 12 '22 at 09:31

2 Answers2

0

It's funny that this problem has been around for 20+ years. After opening CMD, you need to set the environment variable CLASSPATH and include every JAR/directory needed to properly find your server classes, and then start rmiregistry.

Little Santi
  • 8,563
  • 2
  • 18
  • 46
  • so i added to the system variable CLASSPATH following: C:\Users\\Documents\Studium\Module\DistriSys\LectureCodes\out\production\LectureCodes\RMI ( and ..\RMI\DateServer.class) but it still gives me the same error.... what am i doing wrong? didn't work with System Variables until lately – user19094445 May 12 '22 at 09:09
  • p.s.: i startet rmiregistry from within the out, the src dictonary, with windows cmd (admin and normale rights) and from within intellij terminal/console in all combinations.... alwas the same – user19094445 May 12 '22 at 09:22
  • Be careful when selecting the classes directory: If the directory "RMI" corresponds to the first packaging level, you **must not** include it in the classpath: `SET CLASSPATH=C:\Users\\Documents\Studium\Module\DistriSys\LectureCodes\out\production\LectureCodes`. – Little Santi May 12 '22 at 09:26
  • RMI ist the package i createt for the RMI Interface;Server and Client.... tired differents levels, all the same.... i feel a bit lost >.> – user19094445 May 12 '22 at 09:47
  • There exists the file `C:\Users\\Documents\Studium\Module\DistriSys\LectureCodes\out\production\LectureCodes\RMI\DateServer.class`? – Little Santi May 12 '22 at 10:03
  • Yes, also DateServer.class and DateServerImpl.class – user19094445 May 12 '22 at 10:13
0

So I just found a workaround. I used the javac command to compile it over cmd, started the rmiregistry and than the server... and it worked. So I assume it is a Problem of intellij, because .class and .java are in different dictionary and therefore the exception "class not found" makes sense. Now i just need to find a way to reorganize intellij... Thanks for the help so far =D

Edit: Intellij on Windows needs the "out" dictionary to be mirrored(On Linux it seems no problem at all, as long as you started rmiregistry in the same dictionary as your byte code aka .class files are). So Go to

File->Project Structure->Modules->Paths
choose Use module compile output path, and just use out as output

after that, got to intellij terminal, change to the out dictionary, start rmiregistry and than start the server.

That's it, works for me =D.