Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using RMI from within Eclipse

 
Sean Keane
Ranch Hand
Posts: 582
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


 
Sean Keane
Ranch Hand
Posts: 582
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 582
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy, Sean!

Champ, just remember that your application must not require any command line arguments other than the flag that indicates the application mode.
 
Sean Keane
Ranch Hand
Posts: 582
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic