File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Error when sampleproject.remote.RmiFactoryExample is run Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Error when sampleproject.remote.RmiFactoryExample is run" Watch "Error when sampleproject.remote.RmiFactoryExample is run" New topic
Author

Error when sampleproject.remote.RmiFactoryExample is run

Helen Ma
Ranch Hand

Joined: Nov 01, 2011
Posts: 451
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
.....

Please advise.
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1505
    
    5

Hello Helen Ma,

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

I hope this helps.


Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5222
    
  12

I was able to run the example without any problem. Just invoking this call from the command prompt resulted in the given output.

java -cp . sampleproject.remote.RmiFactoryExample

Getting a remote handle to a factory. 963633396
constructing a DvdDatabase object -1083056178
Getting a remote handle to a factory. 935143012
constructing a DvdDatabase object -800921172


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Helen Ma
Ranch Hand

Joined: Nov 01, 2011
Posts: 451
Hi, Roel.

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.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5222
    
  12

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.
Helen Ma
Ranch Hand

Joined: Nov 01, 2011
Posts: 451
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.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5222
    
  12

I had to make same change to make it work.

Glad to hear you were able to figure it out!
 
 
subject: Error when sampleproject.remote.RmiFactoryExample is run