Issue
In a multi-module Maven project can the parent project have implemented java classes in it? If yes, then how do we use those classes in the child project (Since the parent project is packaged as pom)?
Solution
Yes, it can. But they are not going to be built (by default), since the <packaging>pom
creates, well, a .pom
file, no .jar
, .war
, etc.
Furthermore this is an absoulute unusual way of Maven project structure/configuration. I strongly recommend to avoid this under all circumstances since this is working against Maven rather than with it.
Remember also that a multi-module/aggregator project is not (necessarily) a parent of its sub-modules. A project is a parent if other modules declare it as <parent>
. Such a parent can be an aggregator, and often it actually is one, but it doesn't have to be one.
See also POM Reference, Inheritance v. Aggregation:
[...] You often see projects that are both parents and aggregators. [...] However, an aggregator project and a parent project are both POM projects, they are not one and the same and should not be confused. A POM project may be inherited from - but does not necessarily have - any modules that it aggregates. Conversely, a POM project may aggregate projects that do not inherit from it.
Long story short, there are the following relationships:
- Aggregator¹ (
<packaging>pom
) → (sub-)modules ... for, well, aggregation of (sub-)modules - Parent project (
<packaging>pom¹|jar|war|...
) ← child project ... for inheritance (of POM configuration from the parent to the child)
Answered By - Gerold Broser