Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing ejb classes from a war file

 
shawn kennedy
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created a ear file that has many wars within it and a jar file containing the ejb classes.Now i want to access the ejb's present in tht jar from one of my wars.What all am i suppose to do to make this happen
 
Amit M Tank
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whats happenening when you are doing a JNDI lookup and calling the EJB methods? Does it throw some exception?
 
shawn kennedy
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well could you read my question again.I need to know whats to be done in order for me to call an ejb from a war file.I dont know what im supposed to do to make it happen
 
Amit M Tank
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How have you deployed the EJB? Whats the JNDI name of the EJB which you have exposed?

Do the JNDI lookup of the EJB through your client (Servelt/BusinessDelegate) in your wars and call the session bean method. Hope this helps.
 
shawn kennedy
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well have done tht bit what i mean to ask is if i have tht war in the ear how will the war look up the ejbs in the ear file.
 
Sunil Dixit
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi shawn,
It is very simple,Let me tell you step by step:

1. In you JAR file please make it sure that you have given EJB REF i.e. nick name to your EJB. Reason is it is not good to lookup any component by its actual JNDI name beacuse if you do that than your code is tightel coupled with JNDI name,which is wrong.
2. Mentioned those EJB REF in your web.xml file using <ejb-ref> or similar tag (please look on the web ).
3.Now in your servlet class simply do the lookup,rest of all will be taken care by the container itself.
but make it sure that while you do lookup you are using the same ref-name which you have given in web.xml file.

Hope that this will help you.

Cheers,
Sunil Dixit
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic