• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

How to access an EJB session bean outside of EAR in the same app server?

Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm new to EJB3. If I've a stateless session bean like the following:

public interface Cart {

public class CartBean implements Cart {

and I package this EJB bean in an EAR file, and then deploy the EAR in an application server. So, if I've a different web application also deployed in the same server, and want to access to that EJB3 bean inside that EAR file, how do I do that?

I understand that the EJB3 bean is exposed as a MBean, right? So, I should be able to access to that EJB3 bean via InitialContext.lookup(), correct? Or, should use I use something else?
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can access your bean by using dependency injection ... e.g. if you want to access your bean from a servlet present on the same server.. so inside servlet at class level..declare a variable of your bean type as ...

MyBean beanRef;

public void doGet(HttpServleRequest req, HttpServletResponse res)throws...{


the container will automatically assign the SessionObject reference to the variable that you've declared.

See I'm guessing you are not using any deployment descriptor. So just import your package and declare ref variable.

Else you can also do the lookup and get the reference variable.

Here one point is important. If you are not using server specific deployment descriptors then you'll have to use fully qualified remote interface name while doing the lookup. Cuz with this name the bean gets registered in JNDI. Again this JNDI naming of beans is not standardized it's server specific... Glassfish V2 uses fully qualified name of interface for registering the bean in JNDI.

I hope this will solve your problem

    Bookmark Topic Watch Topic
  • New Topic