aspose file tools*
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
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "RMI Projects in Netbeans 6 (setup)" Watch "RMI Projects in Netbeans 6 (setup)" New topic
Author

RMI Projects in Netbeans 6 (setup)

Geoff Prest
Greenhorn

Joined: Feb 20, 2007
Posts: 17
Howdy,

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.

Geoff.
SCJA


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

Joined: Mar 07, 2007
Posts: 1282

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

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

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

Geoff
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1282

You're welcome, Geoff

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

Marco
Dinesh Jayram
Greenhorn

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





dinesh
 
 
subject: RMI Projects in Netbeans 6 (setup)