This content has been marked as final.
Show 4 replies
-
1. Re: EJB3.0 Standalone client
alesj Apr 30, 2006 1:46 PM (in response to manishatjboss)Simple as coding to interfaces.
public class TestEJB { public static void main(String[] args) { TestHelloBean thb = (TestHelloBean) findJndi("gema/TestHelloBeanImpl/remote"); if (thb != null) System.out.println("thb = " + thb.sayHello("Ales")); } private static Object findJndi(String jndiName) { Context context = null; try { context = new InitialContext(); return context.lookup(jndiName); } catch(Exception e) { e.printStackTrace(); return null; } finally { try { if (context != null) context.close(); } catch (NamingException e) { e.printStackTrace(); } } } }
-
2. Re: EJB3.0 Standalone client
manishatjboss Apr 30, 2006 2:04 PM (in response to manishatjboss)thanks for the suggestion. I'm still not entirely clear:
My interface is:@Remote public interface Get { public int get(int key); }
My bean is:@Stateless public class GetBean implements Get { public int get(int key) { return 42+key; } }
My client is??public class Getter { @EJB private static Get getter; /** * @param args */ public static void main(String[] args) { Context ctx = new InitialContext(); getter = ctx.lookup("???"); System.out.println("got: " + getter.get(0)); } }
Is that correct? If so, how do I figure out what the jndi name will be for the above bean.
Thanks again. -
3. Re: EJB3.0 Standalone client
leonell Apr 30, 2006 2:29 PM (in response to manishatjboss)"manishATjboss" wrote:
thanks for the suggestion. I'm still not entirely clear:
My interface is:@Remote public interface Get { public int get(int key); }
My bean is:@Stateless public class GetBean implements Get { public int get(int key) { return 42+key; } }
Client ( "blablabla" is name of your target EAR ):public class Getter { private Get getter; public Getter() { try { Context ctx = new InitialContext(); // used parameters from jndi.properties getter = (Get) ctx.lookup("blablabla/GetBean/remote"); System.out.println("got: " + getter.get(0)); } catch (NamingException e) { System.err.println(""+e); System.exit(0); } } public static void main(String[] args) { new Getter(); } }
And jndi.properties:java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces java.naming.provider.url=localhost
-
4. Re: EJB3.0 Standalone client
manishatjboss Apr 30, 2006 3:34 PM (in response to manishatjboss)thanks. works just right