I followed figure 6-10 on p.183 in Monkhouse book to run the RmiFactoryExample,
But I got this error:
Exception in thread main java.rmi.ConnectException: Connection refused to host ...: nested exception is:
java.net.ConnectException: Connection refused: connect
I don't have access to Monkhouse book right now, and I don't remember the flow given in the book, but a common reason is either registry (rmiregistry) is not started, or not exported at proper port (i.e. wrong arguments to createRegistry method).
Last night, I type java sampleproject.remote.RmiFactoryExample as instructed by the Monkhouse book in one of the figures.
I think we need to start the server. The server is DvdDatabaseImpl.
On one command prompt, I type java DvdDatabaseImpl.
On another command prompt, I type java. sample.project.remote.RmiFactoryExample.
I will go home to try java -cp . sampleproject.remote.RmiFactoryExample tonight.
If you look at the code listing you'll see the registry is created and an instance of server is bound to the registry. So definitely no need to start a server manually.
The -cp . is just setting the classpath to make sure all needed classes are found. Tthe actual value depends oof course on the location where you put your class files and from where you invoke the java-command.
Joined: Nov 01, 2011
Hi, Roel. Thanks for you help.
I found out that in order to make RmiFactoryExample run on my Window 7 machine, I need to change the code into
Naming.rebind("RmiFactoryExample", new DvdDatabaseFactoryImpl("dvd_db.dvd");
In the same directory of the DvdDatabaseFactoryImpl, I put the dvd_db.dvd file there.
Then, it works.
If I use DvdDatabaseFactoryImpl(".") instead, it returns a file not found exception.
I don't know why. "." means current directory. I put the dvd_db.dvd in the current directory where DvdDatabaseFactoryImpl is. But it won't work.