First EJB Hello World


EJB programming & troubleshooting: First EJB Hello World

  1. First EJB Hello World (3 messages)

    I wrote my first EJB and got it successfully deployed in the j2ee Server(accompanying sun's j2ee kit).I also wrote the client side code for the same and the client side code is like this:
    import javax.naming.*;
    import java.util.*;
    import javax.rmi.PortableRemoteObject;

    public class HelloClient
      public static void main(String args[]) throws Exception
          Context cxt = new InitialContext();
            Object obj = cxt.lookup("HelloWorldApp");
              HelloHome home = (HelloHome)
              Hello hello = home.create();

    HelloWorldApp is the JNDI Reference name I entered in the process of deployment and i receive an exception stating that it is unable to identify the Provider name.
    What's to be done.
    Mathi Ezhil

    Threaded Messages (3)

  2. First EJB Hello World[ Go to top ]

    Your client is running outside of the server contexts so instantiating a new Context like that won't work.

    you need to use as a hastable, set the Context.INITIAL_CONTEXT_PROVIDER and Context.PROVIDER_URL and then instantiate the Context passing the hashtable.

    With Weblogic this would look like this :
    Hashtable env = new Hashtable (3);

            env.put (InitialContext.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
            env.put (InitialContext.PROVIDER_URL, "t3://localhost:7001");

            ctx = new InitialContext (env);

    Hope this helps.
  3. First EJB Hello World[ Go to top ]

    As per my earlier posting regarding the helloWorld EJB,i knew the environment variables for weblogic.I need to know the same for the defalut J2EE server provided by sun along with j2ee kit
  4. First EJB Hello World[ Go to top ]

    hmmm, I didn't get that impression from your earlier post :-)
    anyway, I beleive this is what you are looking for :
    props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory");

    props.put(Context.PROVIDER_URL, "iiop://localhost:1050");

    let me know if it works, I never worked with the sun toolkit before :-)