This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Distributed Java and the fly likes RMI Projects in Netbeans 6 (setup) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "RMI Projects in Netbeans 6 (setup)" Watch "RMI Projects in Netbeans 6 (setup)" New topic

RMI Projects in Netbeans 6 (setup)

Geoff Prest

Joined: Feb 20, 2007
Posts: 17

I'd really appreciate some help in filling a blind spot in my Java education. I'm currently beginning study of RMI but am at a loss as far as how to run any of the code examples I come across. I use Netbeans 6 (java 6) for all of my coding.

I'm hoping someone here could give me a run down on how to get an RMI project up and running through Netbeans. To be specific, I'd like to be able to see the examples from HF Design Patterns & HF Java run on my computer. I understand the interactions of the classes invloved and that there is normally the physical separation of a network between the client-side and server-side code, but I'm hoping there might be some way to emulate the operation within my computer.

If I'm completely out to lunch ... how do I go about building and testing code of this nature.

Thanks in advance for your time, any pointers will be fantastic.


SCJP 6, SCJA, SCJD in progress
Marco Ehrentreich
best scout

Joined: Mar 07, 2007
Posts: 1294

Hi Geoff,

I'll try to explain you in short what you have to do in order to create a RMI application with current JDKs (version 5 or 6). There were a lot of changes in recent versions which make the usage of RMI a lot easier. Unfortunately not even Sun's tutorial is up-to-date to reflect all changes. For example it's not necessary any longer to start the RMI registry by hand or generate the necessary class files with the rmic tool. This is all done by the JVM and compiler for you.

So here are the steps to follow...

For the server side:

- create a remote interface for your "remote" methods
- the interface should extend java.rmi.Remote
- all methods have to declare a throws clause for java.rmi.RemoteException
- create a class which implements this remote interface (nothing special to it even it will be remote methods later)

Then somewhere in your server-side code you need to create an instance of this remote-methods-class an export it to the RMI registry so that it can be obtained from remote clients. You can use something like the following code although it's possible to customize for example network specific settings like the protocol or ports used.

So in short you create an object of your implementation class, then you have to "make it ready for remote calls" and finally you export it to the registry so a client can look it up there.

The client side:

The secuirty manager is needed depending on the privileges you have on your machine. Then you should have additionally a Java policy file in your user home. On Linux it is $HOME/.java.policy Unfortunately I don't know where it is on Windows.
The content of the policy file should be something like this:

There are more things to it like automatic class downloading etc. but I hope the examples give you a first idea what to do and get some examples working...

[ June 03, 2008: Message edited by: Marco Ehrentreich ]
Geoff Prest

Joined: Feb 20, 2007
Posts: 17
Thanks Marco,

Once I had the classes all set I ran the server to bind to the RMI registry and then ran the client code. Worked like a charm.

Thanks for your input

Marco Ehrentreich
best scout

Joined: Mar 07, 2007
Posts: 1294

You're welcome, Geoff

As I said RMI is really easy to use nowadays... once you get it

Dinesh Jayram

Joined: Nov 26, 2008
Posts: 23
Where do I get more information on this topic?

I tried to fix the above code in my program but it throws exception

Following exceptions appears while running server program

I agree. Here's the link:
subject: RMI Projects in Netbeans 6 (setup)
jQuery in Action, 3rd edition