How do I lookup from a web application an EJB deployed standalone ?

User Rating: 5 / 5

Star ActiveStar ActiveStar ActiveStar ActiveStar Active
 

Supposing you have deployed an Enterprise Java Bean as stand alone application and you want to access it from your Servlet / Jsp layer. What you need to do is adding the appropriate references to your web.xml and jboss-web.xml.

So if you have an EJB named "HelloBean" add to your web.xml

<ejb-ref>
    <ejb-ref-name>HelloBean</ejb-ref-name>  
    <ejb-ref-type>session</ejb-ref-type>  
    <home>test.HelloBeanHome</home>  
    <remote>test.HelloBeanRemote</remote>  
</ejb-ref>

Then modify jboss-web.xml by adding:

<ejb-ref>
  <ejb-ref-name>HelloBean</ejb-ref-name>  
  <jndi-name>HelloBean</jndi-name>  
</ejb-ref>

Now you can safely lookup your EJB from your Servlet:

Context ic = new InitialContext();
Object ejbHome = ic.lookup("java:comp/env/HelloBean");

Related articles available on mastertheboss.com

EJB 3.0 tutorial : Session Beans

Enterprise JavaBeans (EJB) technology is a J2EE technology for de

JBoss MDB 3.0

Message-driven beans (MDBs) are stateless, server-side, transacti

JBoss EJB 3 BMT

In a Bean Managed Transaction, the code in the session or message

How do you keep your EJB callbacks separated from biz. methods?

JBoss daily recipe

How to set EJB timeout period ?

JBoss recipe of the day

How to add a Selector with MDB 3.0 ?

Message selectors allow an MDB to be more selective about the mes