javaspringmavenspring-integrationmaven-reactor

Spring Multi Module project with single war file where all modules depends only on common module


I am splitting existing spring project into multi module project, where each module depends only on common module and creates a jar file except last one which creates a war file.

Here is the project structure

parent        - packaging -POM, defines module sequence 
common_mod    - common java code i.e. interface , base classes
jar-Mod-1     - depends on common
jar-Mod-2     - depends on common
jar-Mod-3     - depends on common
war-Mod       - depends only on common, this contains java and webapp code

Every project has its own spring context. and last module imports each of them for e.g.

<import resource="classpath*:common-config.xml"/>

Now I want to create single war with all module's jar in it but without defining every module as dependency in final war module. If I specify the same then developers may write the module specific code (say Jar Mod 1 module) in the war module also, which I want to avoid.

Right now when I create war, its containing only common module's jar as it's specified as dependency in war module.

So when I run this project, it complains about the bean not found from other modules which is obvious as war does not contain jars of other module.


Solution

  • Thanks Artem Bilan for the answer,

    You will have add the module dependency in war module, but if you want to ignore them at compile time, but need the jar of that module in the final WAR (which is exactly what I wanted), you have to define the scope of that dependency as runtime.

    Maven : what is the "runtime" scope purpose?