This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes Cannot call EJB from Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Cannot call EJB from Servlet" Watch "Cannot call EJB from Servlet" New topic

Cannot call EJB from Servlet

Joe Cheung
Ranch Hand

Joined: Oct 18, 2002
Posts: 104
I am developing J2EE project in which a servlet calls an EJB on WAS 5.1.x using RSA 6. In the web project, I have made a reference to the EJB project such that there is no syntax error in the web project. A snippet of code is shown as follows:

Object oRef = ic.lookup("ejb/ejbs/HdlrHome");

// Error occurs here
HdlrHome abc = (HdlrHome) PortableRemoteObject.narrow
( oRef, HdlrHome.class );
Hdlr k = abc.create();
String str = k.getString();

The content of the /WebContent/META-INF/MANIFEST.MF is shown below, indicating the web project will reference the EJB Client JAR file "HdlrClient.jar":

Manifest-Version: 1.0
Class-Path: HdlrClient.jar

Finally, I look into the EAR file which already included the WAR file as "Modules" and the EJB Client JAR "HdlrClient.jar" as "Project Utility JARs" that I think the web servlet should be able to call the EJB as the client .class files are already include in the EAR file as a whole.

However, when I run the servlet after deploying the EAR file, WAS server complained the Class "HdlrHome" cannot be found:

E SRVE0026E: [Servlet Error]-[ejbs.HdlrHome]: java.lang.NoClassDefFoundError: ejbs.HdlrHome

Anyone knows why it is so and how to resolve it?

Shailesh Kini
Ranch Hand

Joined: Oct 17, 2001
Posts: 153

You have to use a different way to query for your EJB when you are running it in a container.

java.lang.Object ejbHome =

java: ... is required as per IBM websphere documetation.

IBM documentation

Shailesh Kini.
It is sorta covered in the JavaRanch Style Guide.
subject: Cannot call EJB from Servlet
It's not a secret anymore!