Sunday, October 30, 2011

Calling EJB mehod from java class

public class TestEJBClient {
 

public static void main(String[] args) throws NamingException, CreateException, RemoteException {
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");//put correct server host and port
p.put(Context.PROVIDER_URL, "jnp://localhost:1099");
Context jndiContext = new javax.naming.InitialContext(p);

SessionHome home = (SessionHome) jndiContext.lookup("example1/PublicSession");
Session bean = home.create();
//calling EJB bean method
bean.echo("Hello");
}


}