Discussions

Web tier: servlets, JSP, Web frameworks: ClassCastException when a servlet looks up an EJB (in Weblogic)

  1. hi Friends,
     I deployed an entity bean in Weblogic(4.5). I called the bean frm a servlet.The client servlet works fine when I keet the servlet in the default Weblogic/myserver/servletclasses dir.,but when i try to keep the servlet in some other different dir.(accordingly,i made changes to the "servlet classpath prop." in weblogic.properties file also.),I get ClassCastException exactly at context.lookup(..the home interface..).
    The home interface is also bind properly to it's name.
    Advance thanx for ur help.
  2. Karthik,
    The problem is with the servlet.classpath setting. I believe what is happening is that the ejb gets loaded by the ejb class loader and then the servlet is getting loaded by the servlet classloader (becuase of the servlet.classpath) and eventhough these classes are the same type, they have been loaded by different classloaders so they are in different name spaces and will not cast. I would remove the entry from the servlet classpath.

    Chris
  3. I had the same problem. What I did was, I put the deployment jar file in the (servlet) classpath. Delete any copy of the classes in the jar file, that you may have anywhere else, or at least put the jar file before them, in the classpath.
  4. Are you guys using jikes? What happens is that jikes will compile objects referenced in your JSP and put them where your JSP's are converted/compiled into servlets. This puts two versions of that dependent object in your classpath.