Reputation: 1953
My project has different modules.
When I tried to package using the pom.xml of the parent module, it shows the error - "Packaging jar is invalid Aggregator project need pom as packaging".
What can I do to make an executable jar of the application from maven?
Upvotes: 60
Views: 66201
Reputation: 28706
To make things short: if your parent-aggregator project don't contains source code (and it's a good practice), just add this to your parent pom.xml:
<packaging>pom</packaging>
If the parent project contains source code, I strongly suggest you to:
commons
)commons
a child module of your parent projectcommons
module as a dependency of all other modules requiring it (maybe all of them)<packaging>pom</packaging>
in the parent pom.xmlUpvotes: 110
Reputation: 9118
Maven requires the parent to be of packaging
pom
.
You can make a pom
project behave as if it were a jar
project, by including a bunch of plugin executions and attaching them to their subsequent lifecycle phase. It's not a happy road. On the contrary, the following is.
From an object oriented standpoint, what is it that you want? You have one object that is made up out of a bunch of other objects, right? In other words composition, as opposed to inheritance.
Your final delivery is made up out of the other (jar
) projects, i.e. the other projects are dependencies of the final delivery project. You will define the other projects each as dependency
so that whomever uses your final delivery knows what (transitive) dependencies to get. Alternatively the final delivery jar
could be packaged up as "uber-jar
" and thus contain all its dependencies. That all really depends on how the final delivery is to be used.
At the same time the following two aspects (may) still exist:
parent
configuration in its POM.modules
that are to be easily built in one go. Modules are projects that are referred by use of modules.module
. This is typically (I guess >99%) done in the parent project, but not necessarily. You could put it in the final delivery project also (without affecting inheritance, because that is thus a different beast), but it's atypical and I would not go there.Upvotes: 19