8 Replies Latest reply on Sep 20, 2012 10:13 AM by agerson

    @EJB(lookup="xx") fails.

    agerson

      Sorry ahead of time if this problem is clarified else where.

      Using Eclipse I have created a bean called Foo and a servlet to call it.

       

      package com.foo.ejb;

      import javax.ejb.LocalBean;

      import javax.ejb.Stateless;

        /**

      * Session Bean implementation class Test

      */

      @Stateless

      @LocalBean

      public class Foo implements FooRemote, FooLocal {

           /**

           * Default constructor.

           */

          public Foo() {

              // TODO Auto-generated constructor stub

          }

      }//End of file Foo.java

       

      package com.foo.ejb;

      import javax.ejb.Local;

      @Local

      public interface FooLocal {

      }//End of file FooLocal.java

       

       

      package com.foo.ejb;

      import javax.ejb.Remote;

      @Remote

      public interface FooRemote {

      }//End of file FooRemote.java

       

       

       

      import java.io.IOException;

      import javax.ejb.EJB;

      import javax.servlet.ServletException;

      import javax.servlet.annotation.WebServlet;

      import javax.servlet.http.HttpServlet;

      import javax.servlet.http.HttpServletRequest;

      import javax.servlet.http.HttpServletResponse;

      import org.jboss.logging.Logger;

      import com.foo.ejb.FooRemote;

      /**

      * Servlet implementation class TheServlet

      */

      @WebServlet("/TheServlet")

      public class TheServlet extends HttpServlet {

                private static final long serialVersionUID = 1L;

                private Logger logger = Logger.getLogger(TheServlet.class);

       

        @EJB( lookup="java:global/FooBean/Foo!com.foo.ejb.FooRemote")

                                        private FooRemote foo ;

       

          /**

           * @see HttpServlet#HttpServlet()

           */

          public TheServlet() {

              super();

              // TODO Auto-generated constructor stub

          }

       

       

                /**

                 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)

                 */

                protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

                          logger.info("PlaceBidServlet says hi!");

                }

       

       

                /**

                 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)

                 */

                protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

                          // TODO Auto-generated method stub

                }

      }//End of file TheServlet.java

       

      I used the JBoss log to get the global JINI string and placed into the servlet.


      java:global/FooBean/Foo!com.foo.ejb.FooRemote

      java:app/FooBean/Foo!com.foo.ejb.FooRemote

      java:module/Foo!com.foo.ejb.FooRemote

      java:jboss/exported/FooBean/Foo!com.foo.ejb.FooRemote

      java:global/FooBean/Foo!com.foo.ejb.FooLocal

      java:app/FooBean/Foo!com.foo.ejb.FooLocal

      java:module/Foo!com.foo.ejb.FooLocal

      java:global/FooBean/Foo!com.foo.ejb.Foo

      java:app/FooBean/Foo!com.foo.ejb.Foo

      java:module/Foo!com.foo.ejb.Foo

       

      I am getting the following.

      Caused by: java.lang.NoClassDefFoundError: Lcom/foo/ejb/FooRemote;

      Caused by: java.lang.ClassNotFoundException: com.foo.ejb.FooRemote

       

      This is JBoss version

      JBAS015899: JBoss AS 7.1.1.Final "Brontes" starting

      So I am assuming this type of injection is supported. The test works fine when the client and ejb are in the same project/war but I want to separate them.  Does anybody see what I am doing wrong? Any help would be greatly appreciated.

       

      Thanks, Art

        • 1. Re: @EJB(lookup="xx") fails.
          agerson

          Hi,

          By the number of view and lack of responses can only assume that folks are stumped like me.  Therefore, would the next step be to enter a bug and see if the developers have an idea why this is failing?

          Art

          • 2. Re: @EJB(lookup="xx") fails.
            jaysensharma

            Hi Arthur,

             

                            If you want to deploy EJBs separately on your JBoss as an EJB Jar and then WAR as a separate deployable then in that case you should place the "com/foo/ejb/FooRemote"  class inside your "WEB-INF/classes" directory of your WAR file.

             

                           A similar example is mentioned in the following link:   http://middlewaremagic.com/jboss/?p=822     Where EJBs afre deployed as a separate EAR and  the TestServlet is depoyed as a Separate WAR file.

             

            Thanks

            Jay SenSharma

            1 of 1 people found this helpful
            • 3. Re: @EJB(lookup="xx") fails.
              agerson

              Hi Jay and thanks for the pointer. I looked over the the middlewaremagic example many times before posting this thread but it really did not give me the infro I needed. I am trying to use just induction to get the ejbs to talk and not using any configuration files. I am using Eclipse to build two projects here. One the the client and the other is the bean. Your advice and this URL(http://stackoverflow.com/questions/4631157/eclipse-exporting-jar-in-war) leads on a track to get Eclipse put the EJB jar into the client WAR.  If I get it to work then I will post an update.

               

              Thanks again, Art

              • 4. Re: @EJB(lookup="xx") fails.
                agerson

                To anybody that is viewing this thread and want the outcome here it is.

                 

                The problem was the way the two projects were build in Eclipse. The client project had bean project in the bean path but the deployment was not specified. Therefore, a war and jar were created separately and one could not find the other at run time. To correct the problem use the stackoverflow.com reference above and specify a deployment. This then places the jar in WEB-INF/lib.  Now the client as someplace to look for the jar file and everybody is happy.

                 

                Art

                • 5. Re: @EJB(lookup="xx") fails.
                  wdfink

                  Does a look into this quickstart helps?

                  You will find a JSF and a Servlet calling EJB's

                  • 6. Re: @EJB(lookup="xx") fails.
                    viggo.navarsete

                    You should also perhaps look at the (new) classloading in JBoss 7, since it will force the developer to think about how things are bundled when deployed. If the EJBs are not packaged in the same project as they are referred to, then you must setup an explicit dependency to the EJB module in JBoss!

                    http://www.javacodegeeks.com/2012/09/jboss-as-7-classloading-explained.html

                    • 7. Re: @EJB(lookup="xx") fails.
                      wdfink

                      How do you pack the applications?

                      Could you show where the Bean, the interfaces and the servlet is?

                      • 8. Re: @EJB(lookup="xx") fails.
                        agerson

                        I had two projects in Eclipse.

                        FooBean

                        FooClient

                         

                        The FooClient project was connected in the build path but that did not work.  I had to add FooBean to the Web Deployment Assembly.

                        Properties for FooClient_2012-09-20_10-10-44.png