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
Because 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 Microsoft Windows platforms that directory would be,
C:\SOURCE_DIRECTORY\examples\rmisocfac
In the SolarisTM operating environment, that directory would be,
~/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 JavaTM 2 platform 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
Note: Before you start the
rmiregistry
, you must make sure that the shell or window in which you will run the registry either has no CLASSPATH set or has a CLASSPATH that does not include the path to any classes that you want downloaded to your client, including the stubs for your remote object implementation classes.If you start the
rmiregistry
, and it can find your stub classes in its CLASSPATH, it will ignore the server'sjava.rmi.server.codebase
property, and as a result, your client(s) will not be able to download the stub code for your remote object. For an explanation of how code downloading works in RMI, please take a look at the tutorial on Dynamic code downloading using RMI.
- 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." If you encounter errors starting the server, the likely problems will either be the CLASSPATH of the rmiregistry or that the
java.rmi.server.codebase
property was improperly set.
- 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 ©
1999 Sun Microsystems, Inc. All Rights
Reserved.
Please send comments to: rmi-comments@java.sun.com |