4 Replies Latest reply on Sep 13, 2005 5:53 AM by sergiocg80

    Using external classes inside a EJB

    sergiocg80

      Hi! Here's a simple question about EJB's:

      I have an EAR file containing a WAR file (WEB-INF/lib, WEB-INF/classes, and all that stuff), and a JAR file. The JAR file contains a MDB. A simple scenary, isn't it?

      Well, my MDB uses classes contained in the WEB-INF/classes of the WAR file.

      This works fine in JBoss 4.0.1 and 4.02RC1, but fails (ClassDefNotFound) in 4.0.2.

      Anyway, I find annoying using external classes inside a MDB, and I suppose that I'm doing something pretty bad.

      Can anybody suggest a workarond to this problem? What should be the 'elegant' way to make this work?

        • 1. Re: Using external classes inside a EJB
          sergiocg80

          Sorry, I forgot to say the reason why the classes needed by the MDB are in the war file (web-inf/classes) is that the war application also uses that classes.

          • 2. Re: Using external classes inside a EJB
            darranl

            If you package the classes with the message driven bean jar instead of the war then both should be able to see the classes.

            An EJB tier should not have visibility of the web application so in theory different clients could be used.

            • 3. Re: Using external classes inside a EJB
              sergiocg80

              Thanks for your answer, but it seems that it didn't solve the problem. I moved one of the shared classes (due to a ClassNotFoundException) from the war file to the jar. Now the war can't find the moved class. If instead of moving I try to copy the file, the problem seems to be solved, but another one arises, the jar ask for another class, but instead of throwing a ClassNotFoundException it throws a NoClassDefFoundError. In this case, the trick of moving/copying classes doesn't work.
              Any suggest? By the way, can anybody tell me what's the difference between a ClassNotFoundException and a NoClassDefFoundError?

              Thanks in advance.

              • 4. Re: Using external classes inside a EJB
                sergiocg80

                It works! Your answer was right, what I did was making a JAR with my classes, and put my JAR in the EBJ. All works fine.

                The main difference between a ClassNotFoundException and a NoClassDefFoundError is that in the first case, the classLoader can't find the class. In the second case, the classLoader can find the class, but can't find any other classes used by the first class.

                Thank you.