I wrote a simple implementation class:
public interface MyRemote extends Remote {
public String sayHello() throws RemoteException;
}
Then a remote server class
public class MyRemoteImpl extends UnicastRemoteObject implements MyRemote{
protected MyRemoteImpl() throws RemoteException {
}
public String sayHello() throws RemoteException {
return "Server says 'Hello World!'";
}
public static void main(String args[]) {
try {
MyRemote service = new MyRemoteImpl();
Naming.rebind("RemoteHello", service);
} catch (RemoteException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
} catch (MalformedURLException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
}
Now I read the rmiregistry needs to be started in the same path where the original classes are (and their stubs) so I just compiled using intllij IDEA and auto generated the Stub classes, then copied all the classes to my java path that has the rmiregistry.exe file and then ran the rmiregistry (I know this must be a pretty dumb method but I was just trying to get it to work as a test). I still get an error as listed at the bottom of this post whenever I try and compile the server file.
The book I am working from says to use java's rmic command to generate the stubs and skeletons but I can't find this file (maybe it's from an older version of JAVA?) so I'm just using Intellij IDEA to generate the stub file instead...but no skeleton file is generated.
I'm sure there are several things about RMI I don't understand but I looked up some tutorials online and can't figure out what it is, thought maybe someone on stackoverflow could point me in the right direction. Any help would be much appreciated.
java.rmi.ServerError: Error occurred in server thread; nested exception is: java.lang.UnsupportedClassVersionError: MyRemote : Unsupported major.minor version 51.0 at sun.rmi.server.UnicastServerRef.oldDispatch(Unknown Source) at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source) at sun.rmi.transport.Transport$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.Transport.serviceCall(Unknown Source) at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:273) at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:251) at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:377) at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source) at java.rmi.Naming.rebind(Naming.java:177) at MyRemoteImpl.main(MyRemoteImpl.java:27) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)