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:
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.
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?
[ 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.