Java Jboss服务器中的RMI部署

Java Jboss服务器中的RMI部署,java,rmi,Java,Rmi,我想使用Jboss RMI或JNDI端口1099部署RMI。当Jboss服务器不在使用主程序的picturei.e中时,一切都正常工作。对于服务器上的部署,我尝试了两种方法。 1获取Jboss注册表端口并将RMI注册表绑定到该端口。 下面是我在servlet的init方法中编写的代码 这里的服务器是我扩展远程的接口,ServerImplementor是实现服务器的类 public void init() throws ServletException { {

我想使用Jboss RMI或JNDI端口1099部署RMI。当Jboss服务器不在使用主程序的picturei.e中时,一切都正常工作。对于服务器上的部署,我尝试了两种方法。 1获取Jboss注册表端口并将RMI注册表绑定到该端口。 下面是我在servlet的init方法中编写的代码 这里的服务器是我扩展远程的接口,ServerImplementor是实现服务器的类

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(); } }
您可以检查端口1099是否存在。 可能是,港口已经被封锁了。 尝试通过以下方式指定港口:

LocateRegistry.createRegistry(port);

我已经尝试了createRegistryport和getRegistry。我还检查了它的值,它得到1099。抛出什么异常?这是一个示例:server:reg=LocateRegistry.createRegistry1099;注册人bindTestRMI,c;客户端:reg=LocateRegistry.getRegistrylocalhost,1099;c=计算器如lookupTestRMI;它正在抛出相同的异常。这不会导致此异常。这将导致ConnectException。您在绑定时收到该错误吗?我可以查一下吗?ii关于调用远程方法?
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
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(); }
When i run the client for the 2nd approach it gives error "TestRMI is not bound"
  Client code is:
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); }
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
LocateRegistry.createRegistry(port);