I develop a webapp using a model-view-controller pattern. The model package represents the core API of the application, that could be used independently. The controller and view packages use the model package to produce a webapp.
Question:
I’d like to be able to build a JAR of only the model package, and a WAR of the three packages. And I’d like to keep the three packages in a same project. The webapp WAR would include supplementary libraries as compared to the standalone JAR.
How could I achieve this with Maven? Would there be a solution using for instance two separate pom.xml files? (because as far as I know, you cannot choose two packaging options in the pom.xml)
(I’ve seen this question, but I really want my three packages to be part of a same project, and be part of the same directory.)
Also, my project uses a classical webapp structure (simplified here):
my-app
-- pom.xml
-- src
----- main/
-------- java/
----------- model/
----------- view/
----------- controller/
-------- webapp/
---------- WEB-INF/
-------------classes/
Could I manage to generate the JAR in the classical target/ directory, and the webapp in the classical src/main/webapp/ directory? (and, as asked, including different libraries)
Thanks for your help.
Take a look at Maven Assembly Plugin.
With it you can have as many different Assembly Descriptors as you need, each one customized with its own packaging scheme, filesets and dependencies.
Here is a sample plugin configuration for your pom.xml:
And a sample assembly descriptor for the model jar (
src/main/assembly/model.xml)Running
mvn clean package assembly:singlewill generate both the standard my-app.war file from your project pom.xml and a my-app-model.jar in the target package.