-
Check files
tree . ├── README.md └── example └── hello ├── Client.java ├── Hello.java └── Server.java 2 directories, 4 files
-
Compile java files.
javac example/hello/*.java
-
Run rmiregistry.
rmiregistry
-
Run RMI Server.
java example.hello.Server
-
Run client.
java example.hello.Client response:Hello, World!
-
Run with Jar
-
Prepare
META-INF/MANIFEST.MF
Main-Class: example.hello.Server
-
Make a jar
jar cvfm example-hello.jar META-INF/MANIFEST.MF example/hello/*.class added manifest adding: example/hello/Client.class(in = 1484) (out= 797)(deflated 46%) adding: example/hello/Hello.class(in = 251) (out= 190)(deflated 24%) adding: example/hello/Server.class(in = 1594) (out= 859)(deflated 46%)
-
Run RMI registry (You can skip this step if you use
createRegistry()
instead ofgetRegistry()
)rmiregistry
-
Run server.
java -jar example-hello.jar
-
Run client.
java -cp example-hello.jar example.hello.Client response:Hello, World!
-
java.lang.ClassNotFoundException: example.hello.Hello
: this is because rmiregistry cannot findHello
class. You need to either run rmiregistry in thermi
directory or pass the class path tormiregistry
.java example.hello.Server Server exception: java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: java.lang.ClassNotFoundException: example.hello.Hello
java.rmi.ConnectException: Connection refused to host: 192.168.10.51; nested exception is: java.net.ConnectException: Connection refused
: this is because rmiregistry is not running. You need to either run rmiregistry or changegetRegistry()
tocreateRegistry(1099)
.