views:

51

answers:

2

I imagine this is simple - but I can't find the right combination of search terms to get an answer. If I have a multi-module application, how do I get the beans in module A available to the beans in module B.

The project setup looks a little like this:

project.ear/module-a.jar/resources/beans.xml
project.ear/module-a.jar/java/foo/bar.class
project.ear/module-b.war/java/foo/barFactory.class

The beans.xml isn't accessible by either classpath, or filesystem. Is there a way to do this? Or should I be doing everything differently?

+2  A: 

Your appserver is likely using different classloaders for each module in your EAR, preventing one module from seeing resources in another. This is the default behaviour of JavaEE classloaders.

You either need to

  • reconfigure your appserver to use a "unified" classloader across the whole EAR (which is highly appserver-specific, but great if you can get it to work), or
  • package everything into one module (e.g. your WAR could contain everything), or
  • declare a formal manifest for the WAR module, allowing it to declare the its dependencies on the individual JAR modules, which should allow the WAR to see the resources in the JAR module.
skaffman
A: 

I think there is an easier solution than these 3 skaffman mentioned above.

  1. Put in a module-b.war/WEB-INF/web.xml these lines:

    <context-param>

    <param-name>contextConfigLocation</param-name>

    <param-value>

    classpath*:/resources/beans.xml

    </param-value>

    </context-param>

    This enables loading every /resources/beans.xml from any piece of classpath (i.e. any jar on classpath) which is enough for you.

  2. You should load a module-a.jar as a part of a module-b.war (module-a.jar resides in module-b.war/WEB-INF/lib location).

I have very similar granularity in my project: business-logic.jar with its beans' configuration and frontend.war which uses beans configured in previous one via ref="someBean". It works.

Grzegorz Błaszczyk