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.
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".
- Create your SOURCE_DIRECTORY
- Download the source code into your SOURCE_DIRECTORY
- Change your directory to the SOURCE_DIRECTORY
- Extract the tarfile you downloaded
- Compile all the source files as follows:
javac -d . *.java
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 directoryexamples
- All the compiled .class files, placed in the directory
rmisocfac
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 isexamples.rmisocfac.HelloImpl
. If you've followed the steps up until now, you should be sitting in your SOURCE_DIRECTORY, so to invokermic
, 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
andHelloImpl_Skel.class
will be located in~/SOURCE_DIRECTORY/examples/rmisocfac
.
In this tutorial, the example will be run in three separate windows, or shells; one each for thermiregistry
, the client, and the server.Start the registry, then the server and then the client.
- In each window, change to the SOURCE_DIRECTORY (assuming the package directory,
examples/rmisocfac
is a subdirectory of the SOURCE_DIRECTORY).
- 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.
- To start the
rmiregistry
, choose one of the three windows as the registry window, and type:
rmiregistry
-J-Djava.security.policy=/SOURCE_DIRECTORY/policy
- To start the server, choose a window to be the server window. In that window, type:
java -Djava.security.policy=/SOURCE_DIRECTORY/policy -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."
- To start the client, in the third window, type:
java -Djava.security.policy=/SOURCE_DIRECTORY/policy 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.