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