• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using RMI from within Eclipse

 
Ranch Hand
Posts: 590
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 590
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 590
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 .
 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 590
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic