EJB exception: javax.naming.NoInitialContextE­xception


EJB programming & troubleshooting: EJB exception: javax.naming.NoInitialContextE­xception

  1. I am new to EJB. I am using WSAD v5.12 to develop EJB project. The following HelloWorld example is from Mastering EJB book by Ed Ramon.

    I got the following run time errors. Also, I want to ask if the code need to be changed for different J2EE servers. Please advise. thanks!!

    javax.naming.NoInitialContextE­xception: 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.InitialContext.lo­okup(InitialContext.java:359)
            at HelloEJBClient.main(HelloEJBCl­ient.java:32)
    Exception in thread "main"

    import javax.naming.Context;
    import javax.naming.InitialContext;
    import java.util.Properties;

    public class HelloClient
            public static void main(String[] args) throws Exception
                    Properties props = System.getProperties();
                    Context ctx = new InitialContext(props);
                    Object obj = ctx.lookup("HelloHome");
                    HelloHome home =
    (HelloHome)javax.rmi.PortableR­emoteObject.narrow(obj, HelloHome.class);
                    Hello hello = home.create();
  2. initialcontext exception[ Go to top ]

    try not passing the System.getProperties to the initalContext - use the no-args constructor.
    if that doesn't work, check to see if this is the inital context class for websphere:
    com.ibm.websphere.naming.WsnInitialContextFactory - i recall that's the one u got to register in websphere.