Jan 5, 2009

Write EJB Client

The JNDI could support java client  to get EJB instance from J2EE Container.
We have two type configuration for JNDI. First one,To hardcode properties in program look like listing 1, another one is put properties in file jndi.properties and place on root directory of classes.
Listing 1
Properties props = new Properties();        
props.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
props.setProperty("java.naming.provider.url", "localhost:1099");
InitialContext ctx = new InitialContext(props);
helloworld = (HelloWorld)ctx.lookup("HelloWorldBean/remote");


Listing 2 (jndi.properties)


java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=localhost:1099


Ps. if application depoly on EJB container the container will import jndi properties form default configuration.