tags:

views:

1252

answers:

2

We can run RMI in netbeans by following steps.

Right click build.xml -> Run target -> Other targets -> startRMI

But what i need is to start RMI registry through Java code. Is it possible? Help me.

+1  A: 

In your implementation Class:

YourClass extends UnicastRemoteObject implements YourService {
  ...

  System.setSecurityManager(new java.rmi.RMISecurityManager());
  registry = LocateRegistry.createRegistry( 1099 );
  Naming.rebind("rmiName", this);
}
stacker
This code is working after starting the RMI registry (manually) only. Otherwise it shows the below error java.rmi.ConnectException: Connection refused to host: 192.168.1.35; nested exception is: java.net.ConnectException: Connection refused: connect
Samurai
A: 

You should at first start the 'rmi server' and then the client. For this take a look at this tutorial section 'Implement the server'.

BTW: I would recommend to use hessian library which works over http!! so your admins do not need to explicitely open some ports for your app!

Karussell