10 Replies Latest reply on Oct 2, 2008 1:56 PM by stanton fisque

    custom context for EJB deployment

    stanton fisque Newbie

      i am deploying a standalone EJB3 service (some SLSBs and SFSBs) as a .jar file using the autodeploy mechanism.

      what i want to do is change the context the beans are bound to, without changing the jar name. i have looked at repacking it as an .ear file, but, once again, the deployment context is being bound by the .ear name. is there a way to specify in the deployment descriptors what context the beans should be deployed as.

      n.b. there is no packaged war file, so i do not have a web.xml or jboss-web.xml to specify context in.

      TIA

      == stanton

        • 1. Re: custom context for EJB deployment
          jaikiran pai Master

          By context for EJB, you mean the jndi names, right? If so, have a look at this http://www.jboss.com/index.html?module=bb&op=viewtopic&t=142976

          • 2. Re: custom context for EJB deployment
            stanton fisque Newbie

            that definitely has potential. i was hoping on something more configuration level (xml descriptor, etc.). my goal is to keep the java code container agnostic (all ORM level stuff is done via JPA, all EE bindings are against the sun interfaces, etc.)

            so, is there a way to do what appears in that link (using a jboss specific annotation) via a descriptor tag rather than an annotation.

            TIA

            == stanton

            • 3. Re: custom context for EJB deployment
              jaikiran pai Master

              You can use the jndi-name or local-jndi-name for your bean in the jboss.xml. See the dtd http://www.jboss.org/j2ee/dtd/jboss_4_2.dtd for more details.

              • 4. Re: custom context for EJB deployment
                stanton fisque Newbie

                does jboss support "partial descriptors", wherein, i can just put:

                <session>
                 <ejb-name>MyBean</ejb-name>
                 <jndi-name>context_name/ejb_binding_name</jndi-name>
                </session>
                


                and jboss would do the expected ejb3 auto-deploy magic for the remainder of the attributes (injecting from the annotations or defaults), or is it "all or nothing", wherein, if i use ejb-jar.xml, i have to do the full specification for each bean deployed?

                thank you for your input on this.

                == stanton


                • 5. Re: custom context for EJB deployment
                  stanton fisque Newbie

                  correction, jboss.xml, not ejb-jar.xml

                  • 6. Re: custom context for EJB deployment
                    jaikiran pai Master

                     

                    "sfisque" wrote:
                    does jboss support "partial descriptors", wherein, i can just put:

                    <session>
                     <ejb-name>MyBean</ejb-name>
                     <jndi-name>context_name/ejb_binding_name</jndi-name>
                    </session>
                    


                    and jboss would do the expected ejb3 auto-deploy magic for the remainder of the attributes (injecting from the annotations or defaults)


                    Yes, it does support partial descriptors. You can have a jboss.xml for the jndi-name and the rest can be configured through annotations.


                    • 7. Re: custom context for EJB deployment
                      stanton fisque Newbie

                      one last thing.

                      the examples i've seen thus far (of jboss.xml) seem to bind at the "default" location of "bean_name/local" or "bean_name/remote". none of them appear to be specifying the context of the binding. in order to do that, do i need to prepend the binding with a / so that jboss knows to hook the binding to the root of the jndi tree rather than under the "ear/jar name"?

                      i'll offer a concrete example of what i am doing.

                      if i have warehouse-1.0.10.ear (production rules stipulate that we have to tag build artifacts with their version and build numbers, which is the driver for why i need this guidance) that contains warehouse-1.0.5.jar which contains an ejb named com.acme.Inventory.class, if i deploy it trivially (no jboss.xml and minimal ejb-jar.xml) i should get two bindings in jndi:

                      warehouse-1.0.10/Inventory/local
                      warehouse-1.0.10/Inventory/remote

                      what i want to do is have the beans bind at:

                      warehouse/Inventory/local
                      warehouse/Inventory/remote

                      this way, any clients that are written, do not have to change their jndi lookups when we deploy a new ear file. as long as they get the client side jar with the necessary stubs and primitives, they can make the exact same jndi lookup for the stubs, etc.

                      the brute force solution is to have the deployer rename the ear file when deploying it, but that is error prone and if possible to be avoided.

                      thus, will using the jndi-name and local-jndi-name nodes in the jboss.xml allow me to change the context the beans are bound in and if so, do i need to do anything to make sure they are not bound under the default context of "ear-name".

                      TIA

                      == stanton

                      • 8. Re: custom context for EJB deployment
                        stanton fisque Newbie

                        nm, after surfing the jndi using the sun browser, i noticed that the context does not affect the jndi binding. thus i do not need to worry about the jar or ear name.

                        sorry for the confusion.

                        == stanton

                        • 9. Re: custom context for EJB deployment
                          jaikiran pai Master

                          The default jndi naming for EJB3 beans in JBoss is as follows (excerpt from JBoss EJB3 Trail):



                          * If the application is deployed in a EAR file, the default JNDI name is the EAR-FILE-BASE-NAME/EJB-CLASS-NAME/local for the stub for local interface. For the remote interface (see below), it is EAR-FILE-BASE-NAME/EJB-CLASS-NAME/local.
                          * If the bean is deployed in a JAR file, the JNDI names are EJB-CLASS-NAME/local and EJB-CLASS-NAME/remote.


                          That's the reason why you see the bean bound at warehouse-1.0.10/Inventory/local.

                          "sfisque" wrote:

                          thus, will using the jndi-name and local-jndi-name nodes in the jboss.xml allow me to change the context the beans are bound in and if so, do i need to do anything to make sure they are not bound under the default context of "ear-name".



                          Yes, this will solve your issue. You don't have to do anything additional other than providing a jboss.xml with the jndi-name, to take care of this. Once you provide the jboss.xml with these details, the bean will no longer be bound under the default name.

                          • 10. Re: custom context for EJB deployment
                            stanton fisque Newbie

                            thank you both. your input has been illuminating. i'm sure these are just a case of RTFM, but given our aggressive dev cycle, i've had to cut corners on learning curve wrt to jboss specific details.

                            thank you

                            == stanton