5 Replies Latest reply on Jan 17, 2005 1:25 PM by keros

    How Can I dynimicly load a Class in Session Bean (Stateless

      I encounter a problem.
      I should dynimicly load classes in a EJB.
      I read xml file and parse it ,then I can get a class name---I have packaged the class and the xml file into the ejb's jar file.
      I can get the file as a inputStream by Class.getResourceAsInputStream.
      But later,when I load the class by Class.forname(className), the CalssNotFoundException is threw.
      I change classloader to Thread.currentThread().getContextClassLoader()
      ,but the same exception it threw.

      Can you give some advice or help?

      Thanks you.

        • 1. Re: How Can I dynimicly load a Class in Session Bean (Statel

          The appliction Server is Jboss4.0.
          JDK is 1.42_05.

          I need your help

          • 2. Re: How Can I dynimicly load a Class in Session Bean (Statel

            Maybe I should read jboss4.0 src?

            • 3. Re: How Can I dynimicly load a Class in Session Bean (Statel
              frito

              You must not do a Class.forName, instead use

              Thread.currentThread().getContextClassLoader().getResourceAsStream()
              Thread.currentThread().getContextClassLoader().loadClass()


              If you still encounter problems read the wiki for classloader configuration (http://www.jboss.org/wiki/Wiki.jsp?page=ClassLoadingConfiguration) and check your assembly. There are, with the utmost probability, resources missing.

              • 4. Re: How Can I dynimicly load a Class in Session Bean (Statel
                fredatwork

                You definitely have to load a class as Frito told you :

                Thread.currentThread().getContextClassLoader().loadClass()


                But also, I would consider migrating immediately consider to JBoss 4.0.1.

                I had plenty of problems with JBoss 4.0.0 loading classes of mine dynamically and more generally with the JBoss class loader (e.g. with JBossCache) , expecially for classes included in an EJB jar file, that in turns is itself contained inside an EAR file (like you do). I posted several subjects on this. I received the same exception as you did (class not found !).

                I had test cases working with JBoss 4.0.0 RC2 but not with JBoss 4.0.0. When I migrated to JBoss 4.0.1, evrything went allright as with prior versions to 4.0.0.

                I believed JBoss 4.0.0 class loader was somehat buggy. But JBoss tech leaders said JBoss 4.0.1 only changed some xml config of the class loader (they refered to release notes).

                Fred

                • 5. Re: How Can I dynimicly load a Class in Session Bean (Statel
                  keros

                  I've been having classloader problems as well with 3.2.3 (I've tried w/ 3.2.6 as well). I did the

                  Thread.currentThread().getContextClassLoader().getResourceAsStream()
                  Thread.currentThread().getContextClassLoader().loadClass()
                  


                  which works great. I now get my class loaded just fine. However, I now get a NoClassDefFoundError in the method that calls the method with the above code in it.

                  I know the code works (not including the above) outside of jboss. FYI, the RTE is "java.lang.NoClassDefFoundError: javax/ejb/EJBObject". I can supply a more detailed code example if requested. It just may take some time to cut out the right code.