• 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 ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem referencing EJB in web application on Websphere

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
marc dauncey
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you! This advice is invaluable to me
 
Pradeep bhatt
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 know this defies the law of gravity... but I never studied law." -B. Bunny Defiant tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic