File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes Class Cast Exception while running client program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Class Cast Exception while running client program" Watch "Class Cast Exception while running client program" New topic

Class Cast Exception while running client program

vidya lakshmi

Joined: Jun 22, 2001
Posts: 2
Hi all,
I am working on J2ee1.3 app server, I am able to successfully deploy the bean and able to return the client jar file too, but while exectuing my client program I am facing the below mentioned problem, If any one has worked on it, please share your ideas and help me out.
The exception is as follows:
F:\>java ejbclient
Basic Lookup is Successful....
Got the Object, Final Lookup is Successful....
Caught an unexpected exception!
at Source)
at javax.rmi.PortableRemoteObject.narrow(Unknown Source)
at ejbclient.main(

My Client Program:
import javax.rmi.*;
import javax.naming.*;
import ssrem;
import sshome;
public class ejbclient
public static void main(String args[])
Context initial = new InitialContext();
Object objref = initial.lookup("shiva");
System.out.println("Basic Lookup is Successful....");
System.out.println("Couldn't get the Object");
System.out.println("Got the Object, Final Lookup is Successful....");
sshome home = (sshome)PortableRemoteObject.narrow(objref,sshome.class);
ssrem ob= home.create();
ob.setString("Hello World");
double dd=ob.getDoubles();
int ee=ob.getIntegers();
String str=ob.getString();
System.out.println("The Double Value returned is : "+dd);
System.out.println("The Integer Value returned is : "+ee);
System.out.println("The String Value returned is : "+str);
catch (Exception ex)
System.err.println("Caught an unexpected exception!");
My Doubts:
1. At the time of deploying, it is asking for Local home,Local
rem, remote home, remote rem. I am unable to understand what is the difference between local and remote.
I am new to j2ee, Please help me.
greg philpott
Ranch Hand

Joined: Nov 10, 2000
Posts: 73

A common problem when deploying and using EJBs and servlets is the ClassCastException. ClassCastExceptions can occur when a class of the same name resides in more than one classloader within WebLogic Server. Although the classes may have the same name and use the same bytecode, if the classes are loaded by separate classloaders, they are treated as different classes. A common scenario is as follows:

An EJB provider uses a support class, "Address" in an EJB's public interface. Upon deployment, the EJB classloader exports the EJB's public interface, and also exports the "Address" class, to the WebLogic classloader.
A servlet developer includes an identical "Address" class as part of a servlet deployment. When the servlet class is deployed, the servlet classloader loads and maintains an identical version of the "Address" class.
The servlet invokes the EJB to obtain a new object of the "Address" class. In this case, WebLogic Server yields a ClassCastException error. Because the "Address" class exists in both the WebLogic classloader and Servlet classloader, they are treated as completely different classes.
To correct such ClassCastException errors, EJB and servlet developers must ensure that no two classloaders ever load an identical class. Specifically, you should always ensure that EJB classes reside only in the deployed EJB .jar file or EJB directory, and that they are not included in other EJB .jar files or classpath definitions.
vidya lakshmi

Joined: Jun 22, 2001
Posts: 2
Hi Greg,
Thank you for your reply, I checked my installation and the classpaths, I had set J2EE_HOME,JAVA_HOME(which is jdk1.3 version) in the user environment variables. also, I had set j2ee.jar file in the classpath and bin directory in the path, but could not get the desired result. Please if you had already worked on this, help me out.
Guys, In case, anyone of you have worked on j2ee please do let me know.

Joined: Aug 21, 2002
Posts: 1
I am in trouble with your"
java.lang.ClassCastException at Source)
at javax.rmi.PortableRemoteObject.narrow(Unknown Source)
at ejbclient.main("
Do you have settled it?Can you help me out?Thanks!
skywing us

Joined: Oct 22, 2003
Posts: 1
Thanks greg, you solve my problem. I was having the same problem and spent 2 hours tried to figureout what's wrong and finally see you posting by searching.
I agree. Here's the link:
subject: Class Cast Exception while running client program
jQuery in Action, 3rd edition