4 Replies Latest reply on May 1, 2007 10:03 AM by chensquare

    New to EJB3 -- Please help

    chensquare

      Hi all,

      I'm new to EJB. I'm writing a toy EJB, and having problem running the client (bean can be deployed successfully in Eclipse) When running the client, it generates javax.naming.NameNotFoundException: HelloBean not bound.

      Please help. THANKS A LOT!!!

      my config:
      IDE: Eclipse
      JBOSS: 4.0.5

      //INTERFACE:
      package examples.session.stateless;
      import javax.ejb.*;
      public interface Hello {
      public String hello() ; //throws java.rmi.RemoteException;
      }


      //BEAN CLASS
      package examples.session.stateless;
      import javax.ejb.Remote;
      import javax.ejb.Stateless;
      import javax.ejb.*;
      @Stateless
      @Remote(Hello.class)
      public class HelloBean implements Hello {
      public String hello () {
      System.out.println("in hello()...");
      return "Hello, World!";
      }
      }


      EJB-JAR.XML
      <?xml version="1.0" encoding="UTF-8"?>
      <ejb-jar id="ejb-jar_ID" version="2.1" xmlns="http://java.sun.com/xml/ns/j2ee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd">
      JBoss Hello World Application
      <display-name>HelloBean</display-name>
      <enterprise-beans>
      <ejb-name>HelloBean</ejb-name>
      </enterprise-beans>
      </ejb-jar>



      CLIENT
      package examples.session.stateless;
      import java.util.Hashtable;
      import javax.naming.Context;
      import javax.naming.InitialContext;

      public class HelloEJBClient {
      public static void main( String [] args )
      {
      Hashtable env = new Hashtable();
      env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      env.put(Context.PROVIDER_URL, "localhost:1099");
      env.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");

      try
      {
      InitialContext ctx = new InitialContext(env);
      Hello hello = (Hello) ctx.lookup( "HelloBean" );
      System.out.println(hello.hello());
      }
      catch ( Exception e )
      {
      e.printStackTrace();
      System.out.println( "Chen - Exception: " + e.getMessage() );
      }
      }
      }

        • 1. Re: New to EJB3 -- Please help

          Look at the JMS console if and where the bean might have been deployed.

          Regards

          Felix

          • 2. Re: New to EJB3 -- Please help
            chensquare

            Yes, JMX-Console indicates that bean is deployed properly on the server. Anyone--please help. THANKS A MILLION !!

            • 3. Re: New to EJB3 -- Please help
              kent.narling

              I'm just like you - new to EJB - and got exactly the same problem like you when I tried to disect EJB3Trail and create my own project...

              However, then I downloaded the sample helloworld that this guy did: http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4037705#4037705

              Then it worked!?!
              I have not managed to find out the what was different with what I did yet... but it would be interesting to know!

              AFAIK the default JNDI location should be:
              EAR-FILE-BASE-NAME/EJB-CLASS-NAME/local

              But it just fails to find my Stateless session bean with the error: EJB3Test not bound
              (and the name of my ear file is EJB3Test.ear)

              • 4. Re: New to EJB3 -- Please help
                chensquare

                Thanks Kent. I will try the example that you suggested today.

                It looks like my bean is deployed correctly, and the error is in my client code. I'm sure an experienced EJB programmer can spot my error immediately, I just don't know what else to try (none of the examples that I googled matches my code. I'm trying to follow the example in MasteringEJB3.0 book).