Meaningless Drivel is fun!*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Using RMI from within Eclipse Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Using RMI from within Eclipse" Watch "Using RMI from within Eclipse" New topic
Author

Using RMI from within Eclipse

Sean Keane
Ranch Hand

Joined: Nov 03, 2010
Posts: 581

Hi,

As part of getting up to speed with RMI for the OCJD I am playing around with some examples. I am having difficulty getting an RMI example running in Eclipse, can anyone help?

The example that I am trying to run is from this page here http://download.oracle.com/javase/6/docs/technotes/guides/rmi/hello/hello-world.html

I compiled all the classes from this example into "F:\classes", so they exist in "F:\classes\example\hello". I have the following structure:



The example runs from the command line when I do the following:

1. Run rmiregistry from a command window, where the directory is somewhere other than where the code is located, and CLASSPATH is blank.

2. Run the server using the command, which is run from the directory "F:": java -classpath classes -Djava.rmi.server.codebase=file:F:/classes/ example.hello.Server

3. Run the client using the command below run from the directory "F:" : java -cp classes example.hello.Client

Now, when I copy all the files to Eclipse it no longer runs for me. The directory structure in Eclipse is:



So, I first start the rmiregistry from a command window, where the directory is somewhere other than where the code is located, and CLASSPATH is blank.

Then I attempt to run the Server class in Eclipse. I set the VM arguments to include the following:

-Djava.rmi.server.codebase=file:F:\RMI\classes


But then I get this error below. Any ideas why the class example.hello.Hello cannot be found?





Below is the code that I am trying to run, I've only included the Server class, the Client class and Hello interface are on the link I mentioned above.



SCJP (1.4 | 5.0), OCJP (6.0), OCMJD
Sean Keane
Ranch Hand

Joined: Nov 03, 2010
Posts: 581

Just to note. If I run the rmiregistry from the location my .class files are generated into i.e. "F:\RMI\classes", then the Server class will run from within Eclipse.

But from what I understand, you shouldn't run the rmiregistry from the location where the class files are available, and you shouldn't have the location of the class files on the CLASSPATH environment variable that is available to the rmiregistry. The reason being that the rmiregistry will simply pick up the class files from the current directory or the location on the CLASSPATH rather than the location specified in the JVM argument -Djava.rmi.server.codebase.

I confirmed that the value of -Djava.rmi.server.codebase is being ignored when the rmiregistry is run from the directory containing the class files by setting the value of -Djava.rmi.server.codebase to an invalid value in Eclipse, the Server class still runs, which shows that the value of -Djava.rmi.server.codebase is being ignored.
Sean Keane
Ranch Hand

Joined: Nov 03, 2010
Posts: 581

Ahhh schoolboy error! I was using the following VM argument in Eclipse when attempting to run the Server class:

-Djava.rmi.server.codebase=file:F:\RMI\classes

When I should have been using this:

-Djava.rmi.server.codebase=file:F:\RMI\classes\

Note the extra path separator at the end!

The Server now runs for me successfully in Eclipse based on the information above, happy days .
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2266
    
    3

Howdy, Sean!

Champ, just remember that your application must not require any command line arguments other than the flag that indicates the application mode.


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Sean Keane
Ranch Hand

Joined: Nov 03, 2010
Posts: 581

Cheers Roberto. I will keep that in mind. I've never used RMI before. So at the moment I'm just playing around with it a bit to get a feel for it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using RMI from within Eclipse