3 Replies Latest reply on Jan 29, 2009 5:12 AM by Kevin Conner

    ClassLoader configuration for multiple ESB archives

    Joshua Dev Newbie

      I have a configuration file called META-INF/service.xml in two different ESB applications (packaged in two different .esb archives). When I first tried to load that file using Class.getResource() I got the same copy in both applications. I read about more ClassLoaders in JBoss and saw a forum thread http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4148415#4148415 about making ESB applications scope-deployed. Then it worked fine.

      Now however I have an entirely different JAR archive that contains some logic that uses classes that are in one of the ESB archives. And I have a new problem - I get a ClassNotFoundException because the "new" code inside the JAR can't load classes from scope-deployed ESBs.

      In summary - there are two ESB applications that need to load its own configuration files and a JAR file that has to access classes from one of the ESBs. Is there a way to make it work, apart from ditching scope deployment and making sure the configuration files have distinct names (and that would be somewhat hackish)?

        • 1. Re: ClassLoader configuration for multiple ESB archives
          Kevin Conner Master

          If it is just the classes contained within one of the esbs then you should take those out and place them with the "new" code.

          Anything contained in a scoped class loader will not be visible outside of the scope. It is possible to handle these types of issues in other ways though, depending on what your real requirements are.

          Can you tell us more about what you are trying to achieve?

          • 2. Re: ClassLoader configuration for multiple ESB archives
            Joshua Dev Newbie

            Thanks for your answer Kevin. I actually drew the same conclusion reading some more documentation as you wrote:

            Anything contained in a scoped class loader will not be visible outside of the scope

            and therefore went ahead to change the architecture of my applications.

            I was trying to achieve the following - having one of the scope-deployed ESB applications use a custom library for object conversion. The converter code is in a separately deployed JAR archive and was unable to convert one object to another, because it had no access to the classes from the ESB. I solved the issue by passing a ClassLoader instance from the calling code inside the ESB application to the converter object and using it there in Class.forName().

            I was wondering however what are the possible ways to read a file (let's say a Java properties file) packaged inside an ESB archive. To reach it using standard "new File()" I would have to know the exact location of uncompressed .esb contents in application server's "deploy" folder. And to reach it using Class.getResource() I would have to use scope deployment (which may be undesirable) or otherwise I will get the same file for different ESB applications.

            • 3. Re: ClassLoader configuration for multiple ESB archives
              Kevin Conner Master

              Sounds like you need to use the thread context classloader. If this code is being executed on behalf of the ESB (through one of the services) then it will specify the classloader of the .esb deployment.

              You can also use this to load files from that deployment, using the resource methods.