Compiling and Running the HelloWorld Example


This document will show you how to compile and run a version of the "Hello World" example that was modified to install and use a custom RMISocketFactory.


Compiling the Example

The first step is to create a directory to hold the source files, and to download the source files. If you haven't already completed this step, then please do so now. The directory that you create and download the source files into will be referred to as the SOURCE_DIRECTORY. So, if on your machine, you downloaded the source files into a directory named "test", then when following these instructions, you should substitute the word "test" wherever you see a reference to the "SOURCE_DIRECTORY".

  1. Create your SOURCE_DIRECTORY
  2. Download the source code into your SOURCE_DIRECTORY
  3. Change your directory to the SOURCE_DIRECTORY
  4. Unzip the file you downloaded
  5. Compile all the source files as follows:

    javac -g *.java

    The -g option tells the compiler to add debugging information to the resultant .class files. Since the files from this example all have the package name examples.rmisocfac, the results of the above command are:

    • A directory named examples, created in the SOURCE_DIRECTORY
    • A directory named rmisocfac, created in the directory examples
    • All the compiled .class files, placed in the directory rmisocfac

  • After compiling the source files, we use the RMI compiler, rmic, to produce stub and skeleton code for the remote object implementation server, HelloImpl.

    rmic must be invoked with the fully-qualified package name of the implementation class so in this example, the fully-qualified package name is examples.rmisocfac.HelloImpl. If you've followed the steps up until now, you should be sitting in your SOURCE_DIRECTORY, so to invoke rmic, type:

    rmic examples.rmisocfac.HelloImpl

    When this command completes, the stub and skeleton should be located in the directory with the rest of the .class files.

    On Win32 platforms that would be C:\SOURCE_DIRECTORY\examples\rmisocfac

    On solaris that directory is ~/SOURCE_DIRECTORY/examples/rmisocfac

    After invoking rmic, the .class files for the stub and skeleton, HelloImpl_Stub.class and HelloImpl_Skel.class will be located in ~/SOURCE_DIRECTORY/examples/rmisocfac.

    Now that the code is compiled, and the stub and skeleton are generated, we can move on to running the example.


  • Running the Example

    In this tutorial, the example will be run in three separate windows, or shells; one each for the rmiregistry, the client, and the server.

    1. In each window, change to the SOURCE_DIRECTORY (assuming the top package directory, examples/rmisocfac is a subdirectory of the SOURCE_DIRECTORY).

    2. Next, you need to make sure that the Java runtime knows where to find the executable files. To accomplish this, you'll need to set your CLASSPATH to include the SOURCE_DIRECTORY in all three windows.

      Now, start the registry, then the server and then the client.

    3. To start the rmiregistry, choose one of the three windows as the registry window, and type:

      rmiregistry

    4. To start the server, choose a window to be the server window. In that window, type:

      java examples.rmisocfac.HelloImpl

      You will know that the server started successfully when you see the message, "HelloServer Bound in registry."

    5. To start the client, in the third window, type:

      java examples.rmisocfac.HelloClient

      You will know that the HelloClient program completed successfully when the message "Hello World!" is printed to in that window.



      Copyright © 1996, 1997 Sun Microsystems, Inc. All rights reserved.