14 Replies Latest reply: Oct 12, 2012 4:14 AM by jimbrady RSS

How do I set the JNDI name for EJB 2 in JBoss 7.1?

Duane Silkworth Newbie

We are migrating an application from JBoss 5.1 to JBoss 7.1 (using cr1b).  It uses an EJB 2 stateless session bean.  For JBoss 5.1, the jndi name for the bean was specified in jboss.xml, but in 7.1, this apparently does not take effect.  The EJB is deployed and registered with a default jndi name based on the deployment ear file and ejb jar file names and class name.  Is there a different way to set the jndi name for an ejb 2 session bean?

  • 1. Re: How do I set the JNDI name for EJB 2 in JBoss 7.1?
    jimbrady Newbie

    I'm having the same issue (with entity beans as well). Any progress?

  • 2. Re: How do I set the JNDI name for EJB 2 in JBoss 7.1?
    Duane Silkworth Newbie

    No, we have had no progress.  So far as I know, we need to change the lookup of the EJB in its consumer to use the default JNDI names that JBoss 7 chooses to register.  So, our client code/configuration is different depending whether the EJB container is JBoss 7 or something else, (like JBoss 5.1, WebLogic, or Websphere).  We'd move to use EJB 3.1 where the JNDI names are specified by the standard annotations, but not all the other app servers we need to support right now are ready for EJB 3.1 yet.

  • 3. Re: How do I set the JNDI name for EJB 2 in JBoss 7.1?
    jimbrady Newbie

    Yes,

    I same to the same conclusion (there were some other threads that said this wasn't going to be changed). I'm converting some old applications and going to EJB 3 is a lot of work. What I am doing instead is writing some custom xdoclet scripts to make it a little easier.

  • 4. Re: How do I set the JNDI name for EJB 2 in JBoss 7.1?
    Wolf-Dieter Fink Master

    At the moment there is no customizing of EJB-naming possible for EJB3, I suppose it will be the same for EJB2.

  • 5. Re: How do I set the JNDI name for EJB 2 in JBoss 7.1?
    Michael Rootman Newbie

    I believe, that for session bean Jboss writes default JNDI names in the log and one can adjust lookup accordingly.

    What is still hidden from me is how to know JNDI names for  2.1 entity beans, which previously were defined in jboss.xml and now totally ignored in jbos-ejb3.xml.

     

    Anybody can advise?

  • 6. Re: How do I set the JNDI name for EJB 2 in JBoss 7.1?
    jimbrady Newbie

    I thought I'd post a little more on this to help any other people who come here.

     

    One important issue here is scope (of the JNDI links). I start some tasks in a parallel thread (from the Web Application) and they need the global JNDI links. Mostly though, from the Web Application you can use the app JNDI link to refer to beans in the EJB jar.

     

    The xdoclet custom scripts look like:

     

    local-home-custom.xdt

     

    <XDtEjb:ifIsAConcreteEJBean>
       public static final String JBOSS7_JNDI_NAME="java:app/myEJbModule/<XDtEjb:ejbName/>!<XDtPackage:packageOf><XDtEjbHome:homeInterface type="local"/></XDtPackage:packageOf>.<XDtClass:classOf><XDtEjbHome:homeInterface type="local"/></XDtClass:classOf>";
    </XDtEjb:ifIsAConcreteEJBean>

     

     

    util-custom.xdt

     

       <XDtEjbIntf:ifLocalEjb>
       /**
        * <XDtI18n:getString bundle="xdoclet.modules.ejb.XDocletModulesEjbMessages" resource="util_obtain_localhome_def_ic"/>
        * @return <XDtI18n:getString bundle="xdoclet.modules.ejb.XDocletModulesEjbMessages" resource="local_home_interface_for" arguments="<XDtEjb:ejbName/>"/> <XDtI18n:getString bundle="xdoclet.modules.ejb.XDocletModulesEjbMessages" resource="util_lookup_using" arguments="JBOSS7_JNDI_NAME"/>
        */
       public static <XDtEjbHome:homeInterface type="local"/> getJBoss7LocalHome() throws javax.naming.NamingException
       {
          <XDtConfig:ifConfigParamEquals paramName="cacheHomes" value="true">
          if (cachedLocalHome == null) {
                cachedLocalHome = (<XDtEjbHome:homeInterface type="local"/>) lookupHome(null, <XDtEjbHome:homeInterface type="local"/>.JBOSS7_JNDI_NAME, <XDtEjbHome:homeInterface type="local"/>.class);
          }
          return cachedLocalHome;
          </XDtConfig:ifConfigParamEquals>
          <XDtConfig:ifConfigParamNotEquals paramName="cacheHomes" value="true">
          return (<XDtEjbHome:homeInterface type="local"/>) lookupHome(null, <XDtEjbHome:homeInterface type="local"/>.JBOSS7_JNDI_NAME, <XDtEjbHome:homeInterface type="local"/>.class);
          </XDtConfig:ifConfigParamNotEquals>
       }
       </XDtEjbIntf:ifLocalEjb>

     

    If anybody knows how to tell from within an EJB module how you are running in JBoss 7 (well one way would be to set some global environment variable - but it seems a bit clumbsy), I could make it even better. Now I just need to make a global code change and replace getLocalHome() with getJBoss7LocalHome().

  • 7. Re: How do I set the JNDI name for EJB 2 in JBoss 7.1?
    Sebastiao Santos Newbie

    Jimbrady,

     

    How can I add these XDoclet templates to my build ?

     

    Do you known if there is some effort to create EJB 2.1 deployment descriptors from XDoclet, to JBoss 7.1.1 (jboss-ejb3.xml) ?

     

    []'s

  • 8. Re: How do I set the JNDI name for EJB 2 in JBoss 7.1?
    jimbrady Newbie

    Sebastio,

      These templates are automatically called as long as you tell ejbdoclet where to find them via the mergedir parameter.

     

     

    <

    ejbdoclet destdir=

    "src/generated/java"

     

    mergedir=

    "src/main/resources/META-INF/xdoclet"

     

  • 9. Re: How do I set the JNDI name for EJB 2 in JBoss 7.1?
    Sebastiao Santos Newbie

    Jim,

     

    I'm using XDoclet to process my EJB 2.1 and having some problems when generating jboss-ejb3.xml.

     

    I'm using XDoclet to generate jboss.xml and did a maven plugin to process it with XSLT to generate jboss-ejb3.xml.

     

    Do you know some better approach to obtain jboss-ejb3.xml from XDoclet ?

     

    Thanks,

  • 10. Re: How do I set the JNDI name for EJB 2 in JBoss 7.1?
    jimbrady Newbie

    jboss-ejb3.xml?

     

    XDoclet doesn't know anything about this since it hasn't been developed for several years. (In fact I don't either - what is it needed for? I wrote EJB3 which happily work without it.)

  • 11. Re: How do I set the JNDI name for EJB 2 in JBoss 7.1?
    Sebastiao Santos Newbie

    jboss-ejb3.xml is necessary to bind resource-ref in ejb 2.1.

     

    I'll migrate my code to EJB3, XDoclet is dead, but at this time my client do not support EJB3 and I need to survive with this.

     

    Thanks anyway.

  • 12. Re: How do I set the JNDI name for EJB 2 in JBoss 7.1?
    jimbrady Newbie

    I didn't need jboss-ejb3.xml for my ejb2.1 applications - why do you think you need it?

  • 13. Re: How do I set the JNDI name for EJB 2 in JBoss 7.1?
    Sebastiao Santos Newbie

    I think I need jboss-ejb3.xml to setup the resource-ref names for Connection Factories, DataSources, JCA Connection Factories, etc.

     

    Do I really need this when using ejb 2.1 in JBoss 7.1 ?

     

    After some deployments, it seems to me that JBoss 7 automatically setup some resource ref names, but I'm still studying JBoss 7 deployment. The documentation is poor or null about ejb 2.1 in JBoss 7.

  • 14. Re: How do I set the JNDI name for EJB 2 in JBoss 7.1?
    jimbrady Newbie

    Not sure about everything in that list, but DataSources are defined in standalone.xml. Lots of things are defined in standalone.xml. But JBoss 7.1 still recognises some of the old configuration datasets.