Chapter 3   The Classic Hello World Program

Compile Class Files

The next step is to compile the files just created. I am assuming that all source files are in a directory named HelloWorld. Compile the source files using the command line:

c:\HelloWorld> javac *.java

or

c:\HelloWorld> javac HelloInterface.java HelloServerImpl.java HelloClient.java

 

Create Stub and Skeleton classes using RMIC

The rmic compiler is used to create Stub and skeleton classes. The compiler is invoked with the class name of the remote object class not with the remote interface class. The class must previously have been compiled successfully. In the HelloWorld example, the remote object class is HelloServerImpl. RMIC is launched from a Windows NT/95/98 command prompt in the following form:

c:\HelloWorld> rmic HelloServerImpl

After this command is executed, the Stub and Skeleton classes will be created in the HelloWorld directory, with the names: HelloServerImpl_Skel.class and HelloServerImpl_Stub.class. While creating these classes, the rmic compiler generates the intermediate Java files as HelloServerImpl_Skel.java and HelloServerImpl_Stub.java. You cannot view these files as they are temporary files and rmic will delete these files. If you want to see these files, compile the HelloServerImpl with the following option:

c:\HelloWorld> rmic - keepgenerated HelloServerImpl

The keepgenerated argument retains the generated java source files for the stubs and skeletons. The stub protocol version can also be specified:

  • -v1.1 creates stubs/skeletons for the JDK 1.1
  • -v1.2 creates stubs for JDK 1.2, skeletons are not needed for the JDK 1.2

c:\>rmic [options] classfilename

c:\>rmic -v1.2 classfilename

 

Start the RMI registry, server, and client


Starting the Registry

To start the registry on the server, execute the rmiregistry command. This command produces no output. The registry can be started on Windows NT/95/98 command prompt in the following form:

c:\HelloWorld> start rmiregistry

or

c:\HelloWorld> rmiregistry

To start the registry on a different port, specify the port number from the command line. For example, to start the registry on port 2000 type the following:


start rmiregistry 2000

 

Starting the Server

c:\HelloWorld> start java HelloServerImpl

or

c:\HelloWorld> java HelloServerImpl

If the server is successfully started, it will print the messages "Creating server object" and "server ready".

 

Starting the Client

c:\HelloWorld> java HelloClient


Lights, camera, action

Output should be: "HelloWorld".

 

 

 

RMI BOOK MAIN PAGE                Top

  
Copyright © 2001 www.universalteacher.com