How does the JNDI lookup for the ejb work when the ejb is bound to a different EJB location in sun-ejb-jar.xml?

The lookup is:
java:comp/env/OMParticipantServicesEJB
The acutal JNDI location is:
ejb.omservices.OMParticipantServicesLocalHome

This EJB lookup using JNDI with a layer of indirection

Using the ejb-local-ref tag in web.xml
<web-app>
<ejb-local-ref>
<ejb-ref-name>OMParticipantServicesEJB</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local-home>com.biperf.ejb.participant.OMParticipantServicesLocalHome</local-home>
<local>com.biperf.ejb.participant.OMParticipantServicesLocal</local>
<ejb-link>omservicesEJB.jar#OMParticipantServicesEJB</ejb-link>
</ejb-local-ref>
</web-app>

The actual sun-ejb-jar.xml

<ejb>
<ejb-name>OMParticipantServicesEJB</ejb-name>
<jndi-name>ejb.omservices.OMParticipantServicesLocalHome</jndi-name>
<bean-pool/>
</ejb>

So the app server is smart enough to understand the look ups for java:comp/env/OMParticipantServicesEJB as the lookup for the EJB ‘OMParticipantServicesEJB’ and is able to locate home interface. If you remove the <ejb-local-ref> entry from web.xml, the lookup will fail with NameNotFoundException

More on this here:  http://www.ibm.com/developerworks/websphere/library/bestpractices/increase_app_portability.html

This is for glassfish. Has details about mapping the JNDI name (resource-ref-name) in web.xml with actual JNDI (global):
http://forums.sun.com/thread.jspa?threadID=5411011

You can also read more about this sun-web.xml here: Sun GlassFish Enterprise Server 2.1 Application Deployment Guide

Advertisements

One Response to How does the JNDI lookup for the ejb work when the ejb is bound to a different EJB location in sun-ejb-jar.xml?

  1. suneelgv says:

    This is also the answer to the question posted at
    http://forums.java.net/jive/thread.jspa?messageID=294227&#294227

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: