1

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.

Sohan Soni
  • 1,207
  • 21
  • 35
  • 2
    If you want put JAR into WAR you must define that WAR depends on JAR. That's how it works. I read you have objection against but I don't fully understand the objection. Anyway, I expect the objection is overestimated, because when B depends on A, nothing stop you write A-related code in B. Maybe Jigsaw stop. – michaldo Dec 29 '16 at 13:12
  • All these modules are independent, so at any point of time you should be able to comment out any module from parent pom and the code should still compile. If you have code of individual modules into last module then it will not compile. So even though B depends on A, it's via common module and not direclty. – Sohan Soni Dec 29 '16 at 13:23
  • 1
    I wonder if you know what is scope `runtime` for dependency: http://stackoverflow.com/questions/12272499/maven-what-is-the-runtime-scope-purpose – Artem Bilan Dec 29 '16 at 13:46
  • Thanks Artem Bilan, that helped ! – Sohan Soni Dec 29 '16 at 15:20

1 Answers1

2

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?

Community
  • 1
  • 1
Sohan Soni
  • 1,207
  • 21
  • 35