10 Replies Latest reply on Jan 7, 2009 11:51 AM by acefrehley

    ClassCastException from PortableRemoteObject.narrow in JBoss

    eferreyra

      Hi!

      Im trying to make work the JBoos IDE Tutorial (FiboBean), i acomplish several things like put to work a JBoss AS in e250 Sun server with Solaris 8, i use eclipse with JBoss plugins in my PC (W2000) i can debug from my eclipse the EJB in the appserver, etc.

      My problem is i get a ClassCastException in this code:
      Context ctx = new InitialContext();
      Object ref = ctx.lookup("java:comp/env/ejb/Fibo");
      home = (FiboHome) PortableRemoteObject.narrow(ref, FiboHome.class);

      I dont know where to find this problem (im begginer with Java too) ...
      Using:
      JBoss AS 4.0.3RC1
      Eclipse 3.1.0 Build id: I20050627-1435
      JBossIDE 1.5M2 (mixed with old 1.4.1 features)

      Thanks for any help.
      Enrique Ferreyra

        • 1. Re: ClassCastException from PortableRemoteObject.narrow in J
          jaikiran

          I guess, you have the ejb classes in your .war. Remove these classes from the war and try running

          • 2. Re: ClassCastException from PortableRemoteObject.narrow in J
            eferreyra

            YES, that do it.

            I uncheck "/Tutorial/FiboEJB-client.jar -> WEB-INF/lib" in the FiboWeb.war packing conf. and works !

            Now, can i get some explanation of why that is wrong (i guess the tutorial is for a local AppServer, not a remote, but in more detail...) and why the narrow method fails ?

            Thanks jaikiran!

            • 3. Re: ClassCastException from PortableRemoteObject.narrow in J
              jaikiran

              Similar problem was faced by many others, and following is an extract from one of the replies by darranl:

              When the bean classes are packaged in the jar and the war then,
              the problem is when they are packaged twice is that they get loaded by two different classloaders which makes them look as if they are different.



              • 4. Re: ClassCastException from PortableRemoteObject.narrow in J
                gnokit

                 

                "jaikiran" wrote:
                Similar problem was faced by many others, and following is an extract from one of the replies by darranl:

                When the bean classes are packaged in the jar and the war then,
                the problem is when they are packaged twice is that they get loaded by two different classloaders which makes them look as if they are different.



                I dont understand.
                I also got this problem but still not solve yet
                the war archive should contains
                WEB-INF/classes/ contains the ComputeServlet.class only
                WEB-INF/lib/FiboEJB-Client.jar contains the Component and Home interface classes of FiboBean

                right?

                The FiboEJB.jar contains the Component,Home and the Bean classes of FiboBean

                right?







                • 5. Re: ClassCastException from PortableRemoteObject.narrow in J
                  jaikiran

                  Please post the exception that you are seeing, and also the relevant code

                  • 6. Re: ClassCastException from PortableRemoteObject.narrow in J
                    darranl

                     

                    "gnokit" wrote:

                    I dont understand.
                    I also got this problem but still not solve yet
                    the war archive should contains
                    WEB-INF/classes/ contains the ComputeServlet.class only
                    WEB-INF/lib/FiboEJB-Client.jar contains the Component and Home interface classes of FiboBean

                    right?

                    The FiboEJB.jar contains the Component,Home and the Bean classes of FiboBean

                    right?


                    Wrong, you need to make sure the the jar 'FiboEJB-Client.jar' is NOT packaged within the war.

                    • 7. Re: ClassCastException from PortableRemoteObject.narrow in J
                      gnokit

                       

                      "darranl" wrote:
                      "gnokit" wrote:

                      I dont understand.
                      I also got this problem but still not solve yet
                      the war archive should contains
                      WEB-INF/classes/ contains the ComputeServlet.class only
                      WEB-INF/lib/FiboEJB-Client.jar contains the Component and Home interface classes of FiboBean

                      right?

                      The FiboEJB.jar contains the Component,Home and the Bean classes of FiboBean

                      right?


                      Wrong, you need to make sure the the jar 'FiboEJB-Client.jar' is NOT packaged within the war.


                      I remove Home and Component interfaces classes
                      so the WEB-INF/classes only contains the servlet classes

                      It works....

                      Does the Web Container and EJB Container share the same classpath?
                      i'm using JBoss 4.0.2


                      • 8. Re: ClassCastException from PortableRemoteObject.narrow in J
                        zgwmike

                        I don't think the web container and the ejb container share the same classpath.

                        • 9. Re: ClassCastException from PortableRemoteObject.narrow in J
                          ashok.kadam

                          Hi ,

                          I am getting the same problem.
                          I checked all replies mentioned below.
                          My .war file does not contain any of the EJB classes.

                          Please suggest.

                          Envirnoments:
                          Jboss - 5.0.0.CR1
                          Java version - 1.5.0_13
                          EJB - 2

                          Regards,
                          -Ashok

                          • 10. Re: ClassCastException from PortableRemoteObject.narrow in J
                            acefrehley

                            I experienced the same problem, but I didn't have any jars deployed in the wrong place. My problem was that I wasn't casting to the EXACT interface name that I had annotated with @Remote. My interface was extending from an interface that was annotated with @Remote. It was only when I:

                            1.) Cast to the exact interface that contains the actual @Remote annotation
                            2.) Specified the JNDI lookup name suffixed with /remote

                            Did it finally work for me... Here is the syntax that worked in my case:

                            OrderManager orderManagerEjb = (OrderManager) jndiContext.lookup("OrderManagerBean/remote");
                            


                            Where OrderManager has the @Remote annotation.

                            Hope this helps somebody.