First, create a remote service
1, create the Remote interface, Myremote.java
import java.rmi.*; Public Interface extends remote{ publicthrows remoteexception;}
2. Realize Remote,myremoteimpl.java
Importjava.rmi.*;ImportJava.rmi.server.*; Public classMyremoteimplextendsUnicastRemoteObjectImplementsmyremote{ PublicString SayHello () {return"Server says, ' Hey '"; } PublicMyremoteimpl ()throwsremoteexception{} Public Static voidMain (string[] args) {Try{MyRemote service=NewMyremoteimpl (); Naming.rebind ("Rmi://localhost:1099/hello", service); }Catch(Exception ex) {ex.printstacktrace (); } }}
3, compile. In the directory where the above Java files are located, hold down the SHIFT key, right-click, and select "Open Command Window here" to execute
Javac *.java
4, using rmic to produce stubs.
Rmic Myremoteimpl
5, Start RMI registry.
Rmiregistry
6, start the remote service. Also open a command window to execute
Java Myremoteimpl
Second, the client
Continued
Resources:
1. Hae. "Large Web site technology architecture"
Java RMI Instance