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 java.lang.ClassCastException 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 "java.lang.ClassCastException" Watch "java.lang.ClassCastException" New topic


rohit aggarwal

Joined: Jul 11, 2001
Posts: 21
i have deployed the web application sucessfully in j2ee application server.When i run this application i am getting following errors:
java.lang.ClassCastException at
on this code
Context ic = new InitialContext();
java.lang.Object objref = ic.lookup("java:comp/env/ejb/Category");
catHome = (CategoryHome) PortableRemoteObject.narrow(objref,ejbBeans.CategoryHome.class);
I have been stuck to this for last 4 days.I have searched from net but do not get any clue.
Jay Mistry

Joined: May 19, 2001
Posts: 16
The handle that you are trying to cast is the home interface, instead try to cast the remote interface.
Ilya Dorfman

Joined: Aug 16, 2001
Posts: 3
You must cast it to home interface according to J2EE spec (I tried the remote thing for the heck of it). It just doesn't work. So far I only know one solution: do not use J2EE!
Ilya Dorfman

Joined: Aug 16, 2001
Posts: 3
I was wrong. I solved it by generating stubs for the EJB home. Right-click on the home interface, goto Properties->Build->VisiBroker->Generate IIOP.
rohit aggarwal

Joined: Jul 11, 2001
Posts: 21
hi Dorfman,
i could not able to get you. what are stubs.please clearly explain me step wise.
I am very desperate to solve it.
Manjunath Subramanian
Ranch Hand

Joined: Jul 18, 2001
Posts: 236
Hello Rohit,
The reason you are getting the classcast exception is because the jar file is not on the class path of
your client application.

When you are deployed the application , by clicking on the
"Deploy application" menuitem, did you click on the check box which
said "Return Client.jar"?
You have to do this, as this jar will contain the stubs which
the client needs.After you have done the above and deployed it
put the jar file in the same directory where the client file
is present.This will help you in running the client successfully

And Ilya the J2ee server is not a bad one.I think everone who is
trying to learn EJB should start deploying first on the J2EE server before proceeding to other commericial servers because
this server is good in a academic point of you where you get to see what is happenning(The process run's in front of your eyes giving clues on what is happening on the background)unlike a
server like Weblogic6.0 where you run commands which will do the
job for you but you won't know what exactly happened on the background.
Hope this helps,
P.S Rohit :I think this will also help you in your other question which you had posted regarding the the two ejb's not working concurrently.Put the jar files for both the ejb's in the same directory where your client class file is present.
[This message has been edited by Manjunath Subramanian (edited August 18, 2001).]
[This message has been edited by Manjunath Subramanian (edited August 18, 2001).]
rohit aggarwal

Joined: Jul 11, 2001
Posts: 21
Hi manju,
thanks for helping me,
i want to know one thing from you about directory structure.
when i deploy the application in j2ee,
the web part is stored in root directory i.e j2sdkee1.2.1/public_html/applicationName/*.jsp
here *.class are the javBeans that act as clients to ejbs
and ejb jars are stored in
where jar has sellLoginClient.jar,sellLogin1823703Server.jar andsellLogine6014793825.jar
now if i donot check the return client, i think it automaticaaly creats that client.jar into it.
I have tried what you have told but of no use,
either i am doing it in wrong way.
i am getting one client.jar for one application.
please tell me in steps what i have to do.
i have LoginEJB.class and CategoryEJB.calss plus their homes and Remotes.
LoginBean.class and CategoryBean.class javaBeans acts as cleints for their respective EJBbeans.
two jsp files Login.jsp and category.jsp.
first file of application to be called is category.jsp which checks the sessions for user.
please tell me what i have to do from scratch with there directory structure.
with thanks,

Joined: Aug 18, 2001
Posts: 2
Try giving the full package name
as below
catHome = (ejbBeans.CategoryHome.class) PortableRemoteObject.narrow(objref,ejbBeans.CategoryHome.class);
//Your code is below.
catHome = (CategoryHome) PortableRemoteObject.narrow(objref,ejbBeans.CategoryHome.class);
I agree. Here's the link:
subject: java.lang.ClassCastException
It's not a secret anymore!