2 Replies Latest reply on Sep 6, 2012 7:39 AM by Juergen Scha

    reverse dependency between custom module and application classes / ressources

    Juergen Scha Newbie

      Hi. I'm new to AS7 and the module concept, so actually I'm running into some trouble with my projects. I have read a lot, but I didn't find any solution for my problem...

       

      At first, I have configured a custom module, that I want to use in multiple deployed applications (it implements a framework of our company):

       

      <module xmlns="urn:jboss:module:1.1" name="de.mycompany.framework">

          <resources>

              <resource-root path="myFramework.jar"/>     

          </resources>

          <dependencies>      

          </dependencies>

      </module>

       

      Second, I integrate the module into my applicatiion:

       

      <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">

        <deployment> 

          <dependencies>                      

            <module name="de.mycompany.framework" slot="main"/>            

          </dependencies

        </deployment> 

      </jboss-deployment-structure>

       

      Up to this point, everything is clear, but here comes the "special":

       

      The module has to access some configuration files (example for hibernate or any custom application configuration), that are NOT placed inside the module (e.g. myFramework.jar), but instead they are placed inside my application. I do so, because every application has its own configuration (of course), but uses the same classes to access the configuration files (>>> myFramework.jar). Now the problem is, that every try to access the configuration files within the module, results in a ClassNotFound / RessourceNotFound ... it looks like the configuration files within my project are simply not visible for the configured custom module.

       

      So, the question for me is, how to configure a dependency directed from a module to the application - or is it the totally wrong approach?

       

      I would be grateful for any hint.

       

      Juergen

        • 1. Re: reverse dependency between custom module and application classes / ressources
          jaikiran pai Master

          Juergen, welcome to the forums

          Juergen Scha wrote:

           

           

          The module has to access some configuration files (example for hibernate or any custom application configuration), that are NOT placed inside the module (e.g. myFramework.jar), but instead they are placed inside my application. I do so, because every application has its own configuration (of course), but uses the same classes to access the configuration files (>>> myFramework.jar). Now the problem is, that every try to access the configuration files within the module, results in a ClassNotFound / RessourceNotFound ... it looks like the configuration files within my project are simply not visible for the configured custom module.

           

          It looks like whatever class (present in the module) is loading the (application specific) config file is not using the correct classloader. It should not be using the module's classloader since that obviously won't have access to the application specific resources (as you can see). What you need to do is pass the appropriate application specific classloader along with the application specific config file name to the method that does the loading. That way the loading logic can remain within the class that's packaged in the module's .jar and can still use the right classloaders to load the application specific resources. Something like this:

           

          public class MyCommonClassInAModule {
          
               public InputStream loadResource(final String applicationSpecificResourceName, final ClassLoader applicationClassloader) {
                   ....
                   final InputStream applicationResource = applicationClassloader.getResourceAsStream(applicationSpecificResourceName);
                   if (applicationResource == null) {
                      .... // handle it or throw error
                   }
                   ... // do any other common logic that you want to do
                  return applicationResource;
               }
          ....