-
1. Re: reverse dependency between custom module and application classes / ressources
jaikiran Sep 6, 2012 5:12 AM (in response to schopfa)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; } ....
-
2. Re: reverse dependency between custom module and application classes / ressources
schopfa Sep 6, 2012 7:39 AM (in response to jaikiran)Many thanks, it works. Was excactly what I need.