wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes Problem referencing EJB in web application on Websphere Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Problem referencing EJB in web application on Websphere" Watch "Problem referencing EJB in web application on Websphere" New topic
Author

Problem referencing EJB in web application on Websphere

marc dauncey
Greenhorn

Joined: Jan 15, 2004
Posts: 21
Hi there, I am a beginner with EJBs and I have a question on how to reference an existing EJB running on Websphere from another web application.

I started off with an EJB project containing a stateless session bean that performs a lookup to an oracle database. I then generated an EJB client jar project, which in my understanding, splits out the local and home classes along with any required DTOs. I guessed that any application that needed to access my EJB would need this client JAR.

I've now written a web application that uses the EJB app - if I deploy both the EJB and web app in the same EAR, it works fine.

However, if I create a separate EAR for the web project that also contains the EJB client JAR code (but not the EJB app itself), I get a noclassdef exception for the local ejb classes, despite the EJB client jar being present. I've also ensured that the local EJB is defined in the web deployment descriptor as follows:

<ejb-local-ref id="EJBLocalRef_1128420642844">
<ejb-ref-name>CHIPSearchEJB</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local-home>uk.gov.dh.portal.components.business.search.chip.ejb.CHIPSearchLocalHome</local-home>
<local>uk.gov.dh.portal.components.business.search.chip.ejb.CHIPSearchLocal</local>
<ejb-link>CHIPSearch_EJB.jar#CHIPSearch</ejb-link>
</ejb-local-ref>


Ultimately my EJB app has to be referenced by another application running on an entirely different server, so I need to understand how all this fits together. Do I just need the EJB client JAR and the correct JNDI lookup?

If anyone could shed any light on this, I'd be very grateful - sorry if these questions are basic or have been asked before.

Marc
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8904

If I am not wrong local interfaces can be accessed only if they are packaged in the same ear file. In the 2nd case your web and ejbs are in different ears so this would not work.

Also, since you are planning to move ejb and web application to two different servers local interfaces would not work.You will have to use remote interfaces.


Groovy
marc dauncey
Greenhorn

Joined: Jan 15, 2004
Posts: 21
Thanks for your reply - this does make sense.

So if I want to use the remote interfaces, does this imply that I always need the class files that are part of my EJB project included in the WAR file for the calling web application?

What changes would I need to make to my EJB project to use remote interfaces?


Marc
[ October 04, 2005: Message edited by: marc dauncey ]
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8904

Originally posted by marc dauncey:
Thanks for your reply - this does make sense.

So if I want to use the remote interfaces, does this imply that I always need the class files that are part of my EJB project included in the WAR file for the calling web application?

What changes would I need to make to my EJB project to use remote interfaces?


Marc

[ October 04, 2005: Message edited by: marc dauncey ]


For your client to work you need to include the ejb-client.jar file in the client's classpath. In your case the client is a web app so copy the jar file into the WEB-INF\jar folder. The client jar would include EJB home and remote interfaces and common classes (DTOs).

Make your remote interface extend EJBObject rather than EJBLocalObject, home interface should extend EjbHome rather than EJBLocalHome. All DTOs must be Serialzable since they need to passed across the network. Make necessary changes in ejb-jar.xml and also web.xml. Use remote tags rather than local tags.
marc dauncey
Greenhorn

Joined: Jan 15, 2004
Posts: 21
Thank you! This advice is invaluable to me
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8904

Here is a good article on differences between local and remote interfaces of EJB.
http://www.onjava.com/pub/a/onjava/2004/11/03/localremote.html
marc dauncey
Greenhorn

Joined: Jan 15, 2004
Posts: 21
Sorry, just one more quick question!

I've set up my bean to have remote interfaces and I've now got the ejb client jar that contains these, so far, so good.

However, in WSAD, when I set up the EJB references in the deployment descriptor of the web application, it tells me there are no remote beans - even after importing the client jar.

Again, if I add the EJB project to the same EAR, I can browse and find my bean.

Does this mean I need to work in the same EAR within WSAD, but then exporting a WAR, it should work fine on the server just using the EJB Client Jar?

I think my heads about to explode
marc dauncey
Greenhorn

Joined: Jan 15, 2004
Posts: 21
I finally worked out how to put this together in WSAD.

I had an EJB project and a web project, both in separate EARs. In order to pick up the EJB to create a reference, I had to add it to the web EAR and also import the ejb client jar.

Once I set up the reference, I then removed the EJB project from the web EAR and then it worked fine.

Somehow I think theres another way round this, but as long as its working...

Thank you for all your help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem referencing EJB in web application on Websphere
 
Similar Threads
local JNDI lookup
can't resolve SLSB from local webapp
Referencing EJBs in a JAR file from a WAR
EJB Local home lookup - URGENT
Problem JNDI lookup of EJB from other EJB in same application / jar