I am trying to run this basic RMI
example provided in the Java website:
https://docs.oracle.com/javase/7/docs/technotes/guides/rmi/hello/hello-world.html
And it just won't run because I think it can't find the interface
. It always throws this exception:
java.lang.ClassNotFoundException: Hello
Here is the code for the interface:
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface Hello extends Remote {
String sayHello() throws RemoteException;
}
And the code for the server is
import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
public class Server implements Hello {
public Server() {}
public String sayHello() {
return "Hello, world!";
}
public static void main(String args[]) {
try {
Server obj = new Server();
Hello stub = (Hello) UnicastRemoteObject.exportObject(obj, 0);
// Bind the remote object's stub in the registry
Registry registry = LocateRegistry.getRegistry();
registry.bind("Hello", stub);
System.err.println("Server ready");
} catch (Exception e) {
System.err.println("Server exception: " + e.toString());
e.printStackTrace();
}
}
}
I have added the interface to my classpath as well. My classpath contains the following entries:
- C:\Users\mkris\Desktop\untitled\src\Hello.class
- C:\Users\mkris\Desktop\untitled\src\Hello.java
- C:\Users\mkris\Desktop\untitled\src
I am using the IntelliJ IDE
. My src folder contains the three .java files and the corresponding .class files.
I've been trying to fix this issue for almost an entire day now and it is driving me insane. I'm very close to snapping my laptop in half.
Please help me out.
Thanks!