-
1. Re: how to call ejb from another server/jvm
pumuggel Aug 12, 2011 5:05 AM (in response to everjava)Hello everson,
assuming you try to call a ejb from a remote machine (a jvm other that the one JBoss uses), the following should work:
[01] InitialContext ctx = null;
[02] Properties props = new Properties();
[03] props.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
[04] props.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
[05] props.put("java.naming.provider.url", "jnp://192.168.0.100:1099");
[06]
[07] try {
[08] ctx = new InitialContext(props);
[09] MyEJBRemote ejb = (MyEJBRemote) ctx.lookup("YourEARArchiveName/MyEJB/remote");
[10] } catch (NamingException e) {
[11] e.printStackTrace();
[12] }
You have to adjust the IP-Address in Line 5 that needs to point to your JBoss Server.
In Line 9 you can omit "YourEARArchiveName" in the lookup string of the ctx.lookup() method, if you did not deployed your ejb archive within a ear archive.
Regards
Christoph Hirte