RMI Tips

Here are some auxiliary notes and tips to help get the RMI remote calculator example from Fundamentals of RMI up and running on a pc using netBeans under windows XP (Eclipse should be similar).

Create a directory for the project, say remoteCalc

You're going to need a lot of consoles for this so you want to be able to bring them up quickly in your directory. In XP this is done by navigating to the Command Prompt program from the start menu (it's under Accesories in XP) and create a shortcut, then drop the shortcut into your remoteCalc directory in Windows Explorer. Then edit the properties of the Shortcut so that the Start In box is empty. This will force the command window to come up in your local directory.

You're also going to need the rmic application (the rmi compiler). It's in the jdk bin directory so you either have to have this in your command path or you can create a batch file in you remoteCalc directory. Mine simply has this in it.

"c:\Program Files\jdk1.3.1_07\bin\rmic.exe" %1

That is it invokes rmic by its full path name and passes in a single arguement. By saving this file as rmic.bat I can invoke rmic someFile from the command prompt and the batch file will be found and it will find rmic for me..

Now follow the steps given in the web instructions to create a remote calculator. You can clip the code straight off the web page into NetBeans (or JBuilder) and you can use NetBeans to do the compilation. If you want to use javac directly, the same comments/trick applies as for rmic.

Once you have created all the class files, you will need to invoke the rmiregistry program. The same procedure should be used as was done for rmic. If you have arranged to have the path automatically set to include the java\bin directory, well and good. Otherwise create an rmiregistry.bat file exactly as we did for rmic (except this time no parameter %1 is required as the registry is invoked without arguments).

Now to run your calculator, start up three command windows by double-clicking your shorcut three times.

In the first one type rmiregistry which will either directly invoke the exe file or use your rmiregistry batch file to do it, depending upon which technique you chose.

Then start the server in the second window (java CalculatorServer).

Finally, run the client in the last window (java CalculatorClient).

If all this batch stuff seems like a lot of trouble, relax. Once the batch files are built, they're built. You can copy them into your project directory and they should work fine as long as no-one remaps where the java\bin files are.

mpbl