title: RMI deployment in Jboss server
body: <p>I want to deploy a RMI using the Jboss RMI(or JNDI) port 1099. Every thing is working fine when Jboss server is not in picture(i.e using main program). For deployment on server, I tried 2 approaches.<br/><br/>
  1) Getting the Jboss registry port and binding the RMI registry to that port.
  Following is the code which i have written in the init method of servlet
  (Here Server is my interface which extends Remote,ServerImplementor is class implementing Server)</p>
  
  <pre>
  
      public void init() throws ServletException {
              {
              Server implementor=new ServerImplementor();
              Remote obj = UnicastRemoteObject.exportObject(implementor, 0);
              Registry r=LocateRegistry.getRegistry();
              System.out.println("Registry post::"+r.REGISTRY_PORT);
              r.bind("TestRMI", obj);
              }
              catch(Exception e)
              {
                  e.printStackTrace();
              }
          }
  
  </pre>
  
  <p>The problem with this approach is when i run the client with following code:</p>
  
  <pre>
  
      registry = LocateRegistry.getRegistry("localhost",1099);
              hello = (Server) (registry.lookup("TestRMI"));
  
  </pre>
  
  <pre><code>The error which i get is: java.rmi.ConnectIOException: non-JRMP server at remote endpoint
  
  2) The 2nd approach which i tried is using JNDI, exposing a RMI(This is one approach which i came to know through googling)
  Following is the code for the init method of servlet.Here the protocol used is jnp
  </code></pre>
  
  <pre>
  
      try {
              Server remoteObj=new ServerImplementor();
              Properties properties=new Properties();
              properties.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
              properties.put("java.naming.provider.url", "jnp://localhost:1099");
              properties.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
  
              InitialContext initialContext=new InitialContext(properties);
              initialContext.rebind("TestRMI", remoteObj);
              System.out.println("server up");
  
          } catch (RemoteException e) {
              e.printStackTrace();
          }
          catch(NamingException n)
          {
              n.printStackTrace();
          }
  
  </pre>
  
  <pre><code>When i run the client for the 2nd approach it gives error "TestRMI is not bound"
    Client code is:
  </code></pre>
  
  <pre>
  
      main(){
                          Properties properties=new Properties();
              properties.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
              properties.put("java.naming.provider.url", "jnp://localhost:1099");
              properties.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
              InitialContext initialContext=new InitialContext(properties);
              Server server=(Server)PortableRemoteObject.narrow(initialContext.lookup("TestRMI"), Server.class);
      }
  
  </pre>      
  
  <pre><code>So, i am not able to figure out what is the correct approach for deploying RMI in Jboss. Is it correct to write code in Servlet init method and create a registry.Or we have to use EJB,etc.. If any one have done this before please help me.
  
  Thanks
  </code></pre>