3 Replies Latest reply on Feb 27, 2003 3:03 PM by adrian.brock

    servlet in one ear referencing ejb in another ear

    nobel

      Given the following taken from chapter j2ee.8, "Application Assembly and Deployment":

      app1.ear:
      ejb1.jar Class-Path: ejb1_client.jar
      deployment descriptor contains:
      <ejb-client-jar>ejb1_client.jar</ejb-client-jar>
      ejb1_client.jar
      app2.ear
      ejb1_client.jar
      ejb2.jar Class-Path: ejb1_client.jar
      webapp.war
      webapp.war
      WEB-INF/lib/servlet.jar
      WEB-INF/lib/ejb1_client.jar

      A servlet class in servlet.jar is then trying to "JNDI look up" the home interface of a component in the ejb1.jar module which gives javax.naming.NameNotFoundException: ejb not bound.

      Adding an <ejb-local-ref> entry in web.xml will instead give a deploytime error saying that the ejb/component could not be found.

      If I package the whole shebang into one ear it works. What am I missing?

      /Niklas

        • 1. Re: servlet in one ear referencing ejb in another ear

          A strict reading of the spec (although the wording is
          not clear) requires you to use an <ejb-ref>
          not an <ejb-local-ref> for access outside
          the ear. That is how JBoss interprets it.

          Also, because it is outside the ear, you cannot use an
          <ejb-link> you must specify a <jndi-name> for the
          <ejb-ref> in jboss-web.xml

          Look at docs/dtd/jboss-web_3_0.dtd for more info.

          Regards,
          Adrian

          • 2. Re: servlet in one ear referencing ejb in another ear
            nobel

            Ok, adding an ejb-ref to the ejb of interest in web.xml and then pointing out the JNDI name of that ejb in jboss-web.xml does the trick.

            To my surprise I noticed that my servlet in app1.ear could reference an ejb component in a module in app2.ear if I "JNDI look up" the last part of the complete JNDI name. Just use "ejb/component" instead of "java:comp/env/ejb/component". Is that behaviour something you may count on?

            /Niklas

            • 3. Re: servlet in one ear referencing ejb in another ear

              Yes,

              But it is not the recommended method.

              In principle the war should reference
              java:comp/env/ejb/component

              Then you can later change the dds to point at
              ejb/someOtherComponentThatDoesTheJobBetter
              without recompiling the web component.

              Regards,
              Adrian