1 2 Previous Next 15 Replies Latest reply on Jun 3, 2007 9:59 PM by Ferry Tanu Branched to a new discussion.

    javax.naming.NameNotFoundException: MyEjb3 not bound :(

    Mustafa Newbie

      HI,

      I wrote a simple bare minimum "Hello world" EJB 3.0, and deployed it in JBoss AS 4.0.5 with EJB 3 support.

      I am getting an exception
      "javax.naming.NameNotFoundException: MyEjb3 not bound"

      I am deploying "MyEjb3.ear" file using an ANT script.
      If u need to see build.xml or other XML files I can paste them in next post.

      Note: EJBTrail works perfectly fine in my app server, so I do not think there are any environmental issues.


      here is the code:


      HelloWorldBean.java (Stateless session Bean)

      package com.mustafa.ejb30;
      import javax.ejb.Stateless;
      
      @Stateless
      
      public class HelloWorldBean implements HelloWorldLocal , HelloWorldRemote
      {
       public String sayHello(String name)
       {
       return("Hello "+name +" from your first EJB 3.0 component ...");
       }
      }
      




      HelloWorldLocal.java (Local Interface)
      package com.mustafa.ejb30;
      import javax.ejb.Local;
      
      @Local
      public interface HelloWorldLocal
      {
       public String sayHello(String name);
      }
      




      index.jsp (client jsp)
      <%@page import = "com.mustafa.ejb30.*" %>
      <%@page import = "javax.naming.*" %>
      
      <html>
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
      <title>MyEjb3 test app</title>
      </head>
      
      <body>
      <%
      HelloWorldLocal hw = null;
      InitialContext ctx = new InitialContext();
      hw = (HelloWorldLocal) ctx.lookup("MyEjb3/HelloWorldBean/local");
      
      String message = hw.sayHello("Mustafa!");
      %>
      Message is <%=message%>
      
      </body>
      </html>
      




      Please let me know what am I missing.
      Thanks in advance.
      - Mustafa
      http://mustafak.co.nr

        • 1. Re: javax.naming.NameNotFoundException: MyEjb3 not bound :(
          Mustafa Newbie

          I think my JNDI lookup is wrong,
          I tried all of the following:

          hw = (HelloWorldLocal) ctx.lookup(HelloWorldLocal.class.getName());
          hw = (HelloWorldLocal) ctx.lookup("HelloWorldLocal/local");
          hw = (HelloWorldLocal) ctx.lookup("MyEjb3/HelloWorldLocal/local");
          
          hw = (HelloWorldLocal) ctx.lookup("MyEjb3/HelloWorldBean/local");
          hw = (HelloWorldLocal) ctx.lookup("HelloWorldBean/local");
          


          In all , it says EJB not bound !!

          Is there some way to traverse JNDI Tree in JBoss and see with what name my EJB is getting binded?

          any help will be appreciated.

          Thanks,
          Mustafa


          • 2. Re: javax.naming.NameNotFoundException: MyEjb3 not bound :(
            fhh Expert

            Use the JNDIViewer in the jmx-console.

            Regards

            Felix

            • 3. Re: javax.naming.NameNotFoundException: MyEjb3 not bound :(
              Mustafa Newbie

              I have to say JBoss has worst console compared to any other application server.

              I can nowhere find a list of "deployed applications", even tomcat has this basic but damn important feature in its admin console.

              About the JNDI viewer, i guess you are referring to "service=JNDIView" ??
              When I click on invoke of "Output JNDI info as text"
              (Please correct me if I am wrong )

              I can see:

              java:comp namespace of the MyEjb3.ear/MyEjb3.war application:
              
               +- UserTransaction[link -> UserTransaction] (class: javax.naming.LinkRef)
               +- ORB (class: org.jacorb.orb.ORB)
               +- env (class: org.jnp.interfaces.NamingContext)
               | +- security (class: org.jnp.interfaces.NamingContext)
               | | +- realmMapping[link -> java:/jaas/other] (class: javax.naming.LinkRef)
               | | +- subject[link -> java:/jaas/other/subject] (class: javax.naming.LinkRef)
               | | +- securityMgr[link -> java:/jaas/other] (class: javax.naming.LinkRef)
               | | +- security-domain[link -> java:/jaas/other] (class: javax.naming.LinkRef)
              



              Thats it....nothing specific to my project in "java: Namespace" or "Global JNDI Namespace"
              Nothing anywhere about HelloWorldbean or HelloWorldLocal .
              is that normal ??


              I have been struggling with this simple HelloWorld for more than 2 weeks now!...please help.

              Thanks,
              Mustafa

              • 4. Re: javax.naming.NameNotFoundException: MyEjb3 not bound :(
                Andrew Dale Newbie

                Have you tried binding it to a specific name using the following annotations:

                @LocalBinding(jndiBinding = "<name>")
                @RemoteBinding(jndiBinding="<name>")
                


                then you could look up the name as defined in ""

                Cheers,

                Andy

                • 5. Re: javax.naming.NameNotFoundException: MyEjb3 not bound :(
                  Mustafa Newbie

                  Thank you for your inputs
                  I made following changes

                  package com.mustafa.ejb30;
                  
                  import javax.ejb.Local;
                  import javax.ejb.Remote;
                  import javax.ejb.Stateless;
                  import org.jboss.annotation.ejb.LocalBinding;
                  import org.jboss.annotation.ejb.RemoteBinding;
                  
                  @Stateless
                  
                  @Local ({HelloWorldLocal.class})
                  @LocalBinding (jndiBinding="MyEjb3/HelloWorldLocal")
                  @Remote ({HelloWorldRemote.class})
                  @RemoteBinding (jndiBinding="MyEjb3/HelloWorldRemote")
                  
                  public class HelloWorldBean implements HelloWorldLocal , HelloWorldRemote
                  {
                   //public static final String RemoteJNDIName = HelloWorldBean.class.getSimpleName() +"/remote";
                   //public static final String LocalJNDIName = HelloWorldBean.class.getSimpleName() +"/local";
                  
                   public String sayHello(String name)
                   {
                   return("Hello "+name +" from your first EJB 3.0 component ...");
                   }
                  }
                  



                  and in client JSP I am calling by
                  hw = (HelloWorldLocal) ctx.lookup("MyEjb3/HelloWorldLocal");
                  


                  I get a
                  javax.naming.NameNotFoundException: MyEjb3 not bound
                   org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
                   org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
                   org.jnp.server.NamingServer.getObject(NamingServer.java:543)
                   org.jnp.server.NamingServer.lookup(NamingServer.java:267)
                   org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625)
                   org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
                   javax.naming.InitialContext.lookup(InitialContext.java:351)
                   org.apache.jsp.index_jsp._jspService(index_jsp.java:57)
                   org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
                   javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
                   org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
                   org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
                   org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
                   javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
                   org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
                  



                  or maybe way I package is wrong....
                  or maybe my server just got corrupted !

                  can somebody email me a simple bare minimum HelloWorld working example....with that I can cross check if my server is still sane :)

                  Thanks
                  Mustafa

                  • 6. Re: javax.naming.NameNotFoundException: MyEjb3 not bound :(
                    ruchi thakur Newbie

                    I am new to this topic, but have been looking for the same stuff. I am not sure but as i have read
                    There are a lot of questions about injection not working in AS 4.0 and 4.2. Most of the problems boil down to injection not working the web layer.

                    jboss AS 4.0 and 4.2 are J2EE 1.4 servers with an EJB3 plugin. This means that injection and annotations only work within the EJB3 plugin. To get to your EJBs you still have to perform a JNDI lookup from your servlet / application client.

                    So, i hope u are not using 4.0 or 4.2. Please correct me if i am wrong, as i am just learning.
                    Regards,

                    • 7. Re: javax.naming.NameNotFoundException: MyEjb3 not bound :(
                      Ferry Tanu Newbie

                      Hi Ruchi,
                      I also has the same problem with Mustafa, so in this case are you suggesting that EJB3.0 is not run properly in JBoss yet ? esp in 4.0 an 4.2?
                      Which JBoss AS version do you suggest for running EJB3.0 ?
                      Thank you
                      Regards,
                      Ferry

                      • 8. Re: javax.naming.NameNotFoundException: MyEjb3 not bound :(
                        jaikiran pai Master

                         

                        Thats it....nothing specific to my project in "java: Namespace" or "Global JNDI Namespace"
                        Nothing anywhere about HelloWorldbean or HelloWorldLocal .


                        If thats the case then i dont think your bean has been deployed. See if you can find anything in the server.log file indicating whether your bean was deployed or not.

                        • 9. Re: javax.naming.NameNotFoundException: MyEjb3 not bound :(
                          Andrew Dale Newbie

                          It could also be helpful if you could post the exact structure of the ear archive and what is contained within it e.g. (application.xml contents)

                          Cheers,

                          Andy

                          • 10. Re: javax.naming.NameNotFoundException: MyEjb3 not bound :(
                            Mustafa Newbie

                            Thank you guys for your inputs.

                            Jaikiran,
                            the server.log is miles long, but I guess this could be a culprit.
                            I think I am missing some jar somewhere...

                            ObjectName: jboss.j2ee:service=EJB3,module=MyEjb3.jar
                             State: FAILED
                             Reason: java.lang.NoClassDefFoundError: org/hibernate/util/DTDEntityResolver
                            


                            Ruchi and Ferry:
                            JBoss 4.0.5 with "JEMS install" supports EJB3,
                            since, as mentioned earlier, EJB3Trail.ear is working fine on my server.

                            • 11. Re: javax.naming.NameNotFoundException: MyEjb3 not bound :(
                              Mustafa Newbie

                              after a bit of googling I realized..
                              I was missing "hibernate3.jar" in the lib folder.
                              I added it and Voila.......it worked!

                              Message is Hello Mustafa! from your first EJB 3.0 component ...
                              


                              2 weeks of torture for one damn missing jar file! :)
                              Thank you all for your help.

                              - Mustafa
                              http://mustafak.co.nr


                              • 12. Re: javax.naming.NameNotFoundException: MyEjb3 not bound :(
                                Mustafa Newbie

                                Hi Andy,
                                I am still not sure if the way I package and deploy EJB 3 ear file is correct.

                                EJB 3 has done away with ejb-jar.xml, but there are other xml files like application.xml, jboss.xml, jboss-app.xml, jboss-web.xml....and so on.....


                                here is the exploded structure of my EAR file:

                                tmp60740MyEjb3.ear-contents/
                                 ->META-INF/
                                 ->application.xml
                                 ->jboss-app.xml
                                 ->MANIFEST.MF
                                 ->MyEjb3-exp.war/
                                 ->META-INF/
                                 ->MANIFEST.MF
                                 ->WEB-INF/
                                 ->jboss-web.xml
                                 ->web.xml
                                 ->index.jsp
                                 ->MyEjb3.war
                                 ->MyEjb3.jar
                                
                                MyEjb3.jar when unzipped, further has:
                                 ->META-INF/
                                 ->MANIFEST.MF
                                 ->persistence.xml
                                 ->com/
                                 ->mustafa/
                                 ->ejb3/
                                 ->HelloWorldBean.class
                                 ->HelloWorldLocal.class
                                


                                Please let me know if the location of XML files or anything else is wrong.
                                btw, I do not see any use of jboss.xml ?

                                Thanks,
                                Mustafa

                                • 13. Re: javax.naming.NameNotFoundException: MyEjb3 not bound :(
                                  ruchi thakur Newbie

                                  Hi Ferry,

                                  From what i have read so far, EJB 3.0 is not yet fully supported in AS 4.0.5 or 4.2.
                                  In 4.2 , we may still use it as:
                                  @EJB(name="java:comp/env/ejb/MyBeanLocal")
                                  private MyBeanLocal myBean;

                                  This i have got from other forms posted in here only.

                                  But AS 5.00 Beta version should have @EJB annotation working in the web layer as well, though i haven't tried so far.

                                  Mustafa , i had the same problem as yours. I am using AS 4.0.5. I used the following and it worked.
                                  MyLocalIfc bean = (new InitialContext()).lookup("myEAR/MyremoteBean/remote");

                                  Regards,
                                  Ruchika

                                  • 14. Re: javax.naming.NameNotFoundException: MyEjb3 not bound :(
                                    Ferry Tanu Newbie

                                    Hi Ruchika,
                                    Thank you for your reply.
                                    Sorry, I don't understand where should I put the following suggested statement to ?
                                    @EJB(name="java:comp/env/ejb/MyBeanLocal")

                                    Should I put it in interface, the bean itself or at the client side ?
                                    As I'm new to J2EE, and the condition that there is still a few EJB3 issue in JBoss, do you think I should go ahead with EJB3 or I should go for EJB2.1 ?
                                    Thank you.

                                    Regards,
                                    Ferry

                                    1 2 Previous Next