This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes Accessing ejb classes from a war file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Accessing ejb classes from a war file" Watch "Accessing ejb classes from a war file" New topic
Author

Accessing ejb classes from a war file

shawn kennedy
Ranch Hand

Joined: Oct 31, 2002
Posts: 67
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

Joined: Mar 28, 2004
Posts: 257
Whats happenening when you are doing a JNDI lookup and calling the EJB methods? Does it throw some exception?


Amit Tank
Linked In
shawn kennedy
Ranch Hand

Joined: Oct 31, 2002
Posts: 67
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

Joined: Mar 28, 2004
Posts: 257
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

Joined: Oct 31, 2002
Posts: 67
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

Joined: Sep 22, 2005
Posts: 46
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
 
 
subject: Accessing ejb classes from a war file
 
Similar Threads
Calling EJB From the Client
In VAJ 4, Exporting enterprise beans to EJB 1.1 JAR
How to export EJB 1.1 JAR in VAJ 4?
ClassNotFoundException
Reading external properties file from EJB