Lookup and linking of "local" EJBs has never been so simple as it is now with the new JEE 5 dependency injection features, because now you don't need to do any lookup at all, just use the @EJB annotation in your ejb client classes and the local ejb references will be automatically injected in the appropriate attributes. This is particularly important for the typical Java Eenterprise architecture, where one EAR contains several WARs and JARs and where typically WARs have some dependcy toward the enterprise components distributed between the multiple JARs.
With the new annotation based dependency injection features you can inject local ejb into any kind of front end component, instrumenting servlets, jsf managed beans, pojosr or even other enterprise beans and you don't need any declarative deployment descriptor or any explicit dependency lookup to achieve all of this.
Accessing the bean environment in EJB 3.0 session beans
Using Dependency Injection in Java EE5.0
This whole picture is just delicious compared to the intricacies of dependency lookups and deployment descriptions that we had to do in J2EE 1.x. Now we can really start designing with "domain entities".
...
So, i was starting the development of a new JBoss 4.2 web application, using jsf and managed beans on the front-end, not Seam. When the troubles with the @EJB annotation, the local ejb injection and the managed beans started.
A jsf managed bean located in the application (EAR) WAR instantiates entity 3.0 beans and needs to persist these entities using a stateless ejb that is deployed in a JAR within the same application (:within the same EAR). The stateless ejb is just a local stateless persistency facade for the entities to be persisted, being injected of the persistency context EntityManager that it will use to persist the entities that receives from the managed bean.
By the JEE 5 specification I must be able to inject the stateless ejb reference into my jsf managed bean or any other class within the same ejb EAR by simply using the @EJB annotation right over the attribute declaration that I want to inject. In alternative, if I am old fashioned guy or I a masochistic one (and probably I am, but fortunately not up to that point), I could try using the old style XML deployment declarations, using the <ejb> tag in the ejb JAR ejb-jar.xml and the <ejb-reference> tag in the WAR web.xml as it should be still supported (as even confirmed by the Glassfish community).
After 8 hours struggling with the @EJB and with any other kind of alternative declarative XML-ish and exotic lookup configuration without any success (after a hundred of NameNotFoundException and deploy errors) finally i find the reason of my troubles at a JBoss webpage:
@EJB annotations are usable in servlets and JSPs, but unfortunately, we have not yet updated tomcat to support it. Also, Tomcat works with the old XML format so you cannot use XML either (:OOouch!). So for now, you must lookup the EJB via its global JNDI name. This is not compliant, but if you abstract out enough you'll be fine.
Fortunately the webpage explains how to lookup the ejb from WARs classes, it doesn't require any deployment effort and I can confirm that finally it works fine.
...
Some JBoss references:
how to configure datasources in jboss 4.x
JBoss getting started