File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes javax.naming.NoInitialContextException while Running the client Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "javax.naming.NoInitialContextException while Running the client" Watch "javax.naming.NoInitialContextException while Running the client" New topic

javax.naming.NoInitialContextException while Running the client

Mukesh Sheoran

Joined: Nov 24, 2008
Posts: 12
I am running a simples EJB program using NetBeans.. server GlassFish. I created the session bean, home and remote interface and then deployed it I deployed successfully. then I wrote this client class and tried to invoked the Bean method. while running the class the I am getting this exception

javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(
at javax.naming.InitialContext.getDefaultInitCtx(
at javax.naming.InitialContext.getURLOrDefaultInitCtx(
at javax.naming.InitialContext.lookup(
at Examples.HelloClient.invoke(
at Examples.HelloClient.main(

Client Class code is :

package Examples;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;

* @author mukesh
public class HelloClient {

public static void main(String [] args){
new HelloClient().invoke();


public void invoke(){

Context ic = new InitialContext();
Object o = ic.lookup("HelloWorldBean");
HelloWorldRemoteHome home = (HelloWorldRemoteHome) PortableRemoteObject.narrow(o, HelloWorldRemoteHome.class);

HelloWorldRemote remote = home.create();
System.out.println("We run our first EJB>>>"+remote.invokeHello());
}catch(Exception e){

Please help me out.. Thanks in advance
vijay saraf
Ranch Hand

Joined: Jan 08, 2005
Posts: 141
try this :
Object o = ic.lookup("ejb/HelloWorldBean");

Vijay Saraf.
I agree. Here's the link:
subject: javax.naming.NoInitialContextException while Running the client
jQuery in Action, 3rd edition