6 Replies Latest reply on Nov 14, 2012 7:21 AM by michael_jboss

    Uses remote ejb bean in servlet from EAR file.

    michael_jboss

      I have a web project test.war and have ejb's(jar's files) in test.ear.

      I am going to deploy test.war and test.ear singly into jboss 7.

      How am i can uses ejb in my test.war?

       

       

      How I did:

       

      public class MyServlet extends HttpServlet{

           @EJB

           private MyBeanRemoteInterface remoteBean;      

      }

       

      So the servlet does not work.

      For it servlet i have to put my test.war into test.ear, but it badly for me.

       

      I am sorry for my English!

        • 1. Re: Uses remote ejb bean in servlet from EAR file.
          nickarls

          So are you saying that you have a test.war and then you have another ear with jars in the lib (and MyBeanRemoteInterface is defined in one of those)?

          And ther servlet in the war doesn't find the EJB to inject?

           

          I think you need to give the injection point some more information, have you tried something like

           

          @EJB(lookup = "ejb:app/module/distinct/BeanName!View")

           

          (where the lookup corresponds to your bean?)

           

          Check the JBoss AS documentation for the correct lookup string.

          • 2. Re: Uses remote ejb bean in servlet from EAR file.
            michael_jboss

            So are you saying that you have a test.war and then you have another ear with jars in the lib (and MyBeanRemoteInterface is defined in one of those)?

            And ther servlet in the war doesn't find the EJB to inject?

            Yes, all so.

             

            @EJB(lookup = "ejb:app/module/distinct/BeanName!View")

            I used attribute lookup in EJB annotation.

            I had exception when deploying my test.war(ClassNotFoundException: MyBeanRemoteInterface ) because the WAR was without EJB JAR. Next I put EJB JAR in WAR and all worked.

             

            But I am not want copy out my EJB JAR into EAR and WAR(I want only copy out my EJB JAR in EAR).

             

            Do I can uses configuration xml files in my web project, for  dependency on EJB JAR.

            • 3. Re: Uses remote ejb bean in servlet from EAR file.
              nickarls

              Since the WAR and the EJB could in theory be deployed on separate hosts and the client would need the signature of the EJB remote interface in any case, how about splitting the required interfaceparts into a separate jar that is used both in the WAR and the EAR?

               

              I'm not using remote EJBs so I'm not sure what is the best practice, just looking at the problem from a classloading-point-of-view

              • 4. Re: Uses remote ejb bean in servlet from EAR file.
                michael_jboss

                ... so I'm not sure what is the best practice

                I also

                I am going to think on my architecture.

                 

                Thank you Nicklas.

                 

                I am sorry for my English!

                • 5. Re: Uses remote ejb bean in servlet from EAR file.
                  jaikiran

                  Nicklas Karlsson wrote:

                   

                  Since the WAR and the EJB could in theory be deployed on separate hosts and the client would need the signature of the EJB remote interface in any case, how about splitting the required interfaceparts into a separate jar that is used both in the WAR and the EAR?

                  That's how it's supposed to be done. The jar containing the bean interfaces is typically in a separate jar which can then be packaged in individual applications.

                  • 6. Re: Uses remote ejb bean in servlet from EAR file.
                    michael_jboss

                    Nicklas Karlsson wrote:

                     

                    Since the WAR and the EJB could in theory be deployed on separate hosts and the client would need the signature of the EJB remote interface in any case, how about splitting the required interfaceparts into a separate jar that is used both in the WAR and the EAR?

                    That's how it's supposed to be done. The jar containing the bean interfaces is typically in a separate jar which can then be packaged in individual applications.

                     

                     

                     

                    Ok, I am going to do it. Thank you.