3 Replies Latest reply on Apr 14, 2013 9:03 PM by sfcoy

    Module classloader issue

    marcelomrwin

      I'm facing a big problem because JBoss 7.1.1.Final classloader model. I have created a module for a lot of third party libraries that my web application use. So, I created the jboss-deployment-structure.xml file and put the dependency from these module. However my project use groovy jar. For some reason this jar need to load some of my classes, then the problem rises. The module of my third party libraries does not know any of my classes thas is packaged in my web-inf/classes. Then, every time I need to use groovy a ClassNotFoundException rises from local module loader. How can I fix this?

        • 1. Re: Module classloader issue
          sfcoy

          Unless the groovy api provides a mechanism for passing it a classloader I don't believe that you can do that.

           

          You will need to move the groovy jar into the WEB-INF/lib directory, which shares the same classloader as WEB-INF/classes.

          1 of 1 people found this helpful
          • 2. Re: Module classloader issue
            marcelomrwin

            That's exactly what I think. Clearly the new classloader model of jboss bring to us some of benefit, on the other hand some problems too. Every third party jar what we want integrate with our application we need to think if they support control over classloader or we have to put then inside our web-inf/lib. In my case, I have modified the groovy-all-2.0.4.jar, more especifically the class org.codehaus.groovy.runtime.callsite.CallSiteClassLoader, where I changed the method "protected synchronized Class loadClass(String name, boolean resolve)" and solve my problem. follows the complete method:

             

            protected synchronized Class loadClass(String name, boolean resolve)
                                          throws ClassNotFoundException {
                                if (KNOWN_CLASSES.contains(name))
                                          return getClass().getClassLoader().loadClass(name);
                                else {
                                          try {
                                                    return super.loadClass(name, resolve);
                                          } catch (ClassNotFoundException e) {
                                                    try {
                                                              return getClass().getClassLoader().loadClass(name);
                                                    } catch (ClassNotFoundException cnfe) {
                                                              return Thread.currentThread().getContextClassLoader()
                                                                                  .loadClass(name);
                                                    }
                                          }
                                }
                      }
            
            • 3. Re: Module classloader issue
              sfcoy

              That's great!

               

              Please consider submitting a patch to the groovy project.

               

              You would have had the same problem if groovy.jar was added as a utility library to an EAR module (on any appserver platform), so your solution is not necessarily JBoss specific.