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 RMI socket factory.

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.

For all of the source code used in this tutorial, you may choose from the following formats:

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. Extract the tarfile you downloaded
  5. Compile all the source files as follows:
  6. javac -d . *.java

    Since the files from this example all have the package name examples.rmisocfac, the results of the above command are:

  • After compiling the source files, 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 -d . 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.

    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 package directory, examples/rmisocfac is a subdirectory of the SOURCE_DIRECTORY).

    3. 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.

    Start the registry, then the server and then the client.
    1. To start the rmiregistry, choose one of the three windows as the registry window, and type:
    2. rmiregistry

    3. To start the server, choose a window to be the server window. In that window, type:
    4. java -Djava.rmi.server.codebase=file:/SOURCE_DIRECTORY/ 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:
    6. 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 © 1998 Sun Microsystems, Inc. All rights reserved.