What is "pom" packaging in maven?
Asked Answered
L

10

208

I was given a maven project to compile and get deployed on a tomcat server. I have never used maven before today, but I have been googling quite a bit. It seems like the top level pom.xml files in this project have the packaging type set as pom.

What am I supposed to do after mvn install to get this application deployed? I was expecting to be able to find a war file somewhere or something, but I guess I am looking in the wrong place or missing a step.

Lundberg answered 7/10, 2011 at 19:45 Comment(1)
mvn install - this is used for install your artifact (jar, war, ear) in your local repository (usually it'll be ~/.m2/repository direcotry)Flickertail
M
172

pom is basically a container of submodules, each submodule is represented by a subdirectory in the same directory as pom.xml with pom packaging.

Somewhere, nested within the project structure you will find artifacts (modules) with war packaging. Maven generally builds everything into /target subdirectories of each module. So after mvn install look into target subdirectory in a module with war packaging.

Of course:

$ find . -iname "*.war"

works equally well ;-).

Money answered 7/10, 2011 at 19:51 Comment(2)
Just to add a quick comment, there are other packaging types that can exist other than "war". A very common packaging type that could be use in place of "war" is "jar". If you replace every instance of "war" in this answer with "jar", you will get the gist. Read more about packaging types here: baeldung.com/maven-packaging-typesCollotype
Hi @MattC. how do we deploy the app then. I see that one of the apps has 7 to 8 submodules and target folder of each has a jar or war.Andersen
D
59

pom packaging is simply a specification that states the primary artifact is not a war or jar, but the pom.xml itself.

Often it is used in conjunction with "modules" which are typically contained in sub-directories of the project in question; however, it may also be used in certain scenarios where no primary binary was meant to be built, all the other important artifacts have been declared as secondary artifacts

Think of a "documentation" project, the primary artifact might be a PDF, but it's already built, and the work to declare it as a secondary artifact might be desired over the configuration to tell maven how to build a PDF that doesn't need compiled.

Doting answered 17/7, 2012 at 14:57 Comment(2)
Other example which I can think of in similar lines as pom project ==> abstract class and module(s) inside it ==> concrete class(s).Hypophysis
POM stands for Project Object Model. It is fundamental unit of work in Maven. It is an XML file that resides in the base directory of the project as pom.Elemental
L
27

Packaging of pom is used in projects that aggregate other projects, and in projects whose only useful output is an attached artifact from some plugin. In your case, I'd guess that your top-level pom includes <modules>...</modules> to aggregate other directories, and the actual output is the result of one of the other (probably sub-) directories. It will, if coded sensibly for this purpose, have a packaging of war.

Lighter answered 7/10, 2011 at 19:51 Comment(1)
What do you mean by "whose only useful output is an attached artifact from some plugin" ?Falda
P
11

Packaging an artifact as POM means that it has a very simple lifecycle

package -> install -> deploy

http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html

This is useful if you are deploying a pom.xml file or a project that doesn't fit with the other packaging types.

We use pom packaging for many of our projects and bind extra phases and goals as appropriate.

For example some of our applications use:

prepare-package -> test -> package -> install -> deploy

When you mvn install the application it should add it to your locally .m2 repository. To publish elsewhere you will need to set up correct distribution management information. You may also need to use the maven builder helper plugin, if artifacts aren't automatically attached to by Maven.

Pennell answered 28/8, 2014 at 9:52 Comment(0)
D
10

To simply answer your question when you do a mvn:install, maven will create a packaged artifact based on (packaging attribute in pom.xml), After you run your maven install you can find the file with .package extension

  • In target directory of the project workspace
  • Also where your maven 2 local repository is search for (.m2/respository) on your box, Your artifact is listed in .m2 repository under (groupId/artifactId/artifactId-version.packaging) directory
  • If you look under the directory you will find packaged extension file and also pom extension (pom extension is basically the pom.xml used to generate this package)
  • If your maven project is multi-module each module will two files as described above except for the top level project that will only have a pom
Dino answered 7/10, 2011 at 20:16 Comment(0)
S
7

I suggest to see the classic example at: http://maven.apache.org/guides/getting-started/index.html#How_do_I_build_more_than_one_project_at_once

Here my-webapp is web project, which depends on the code at my-app project. So to bundle two projects in one, we have top level pom.xml which mentions which are the projects (modules as per maven terminology) to be bundled finally. Such top level pom.xml can use pom packaging.

my-webapp can have war packaging and can have dependency on my-app. my-app can have jar packaging.

Shellbark answered 9/4, 2015 at 6:52 Comment(0)
B
4

Real life use case

At a Java-heavy company we had a python project that needed to go into a Nexus artifact repository. Python doesn't really have binaries, so simply just wanted to .tar or .zip the python files and push. The repo already had maven integration, so we used <packaging>pom</packaging> designator with the maven assembly plugin to package the python project as a .zip and upload it.

The steps are outlined in this SO post

Belford answered 5/1, 2018 at 16:35 Comment(0)
P
4

“pom” packaging is nothing but the container, which contains other packages/modules like jar, war, and ear.

if you perform any operation on outer package/container like mvn clean compile install. then inner packages/modules also get clean compile install.

no need to perform a separate operation for each package/module.

Parrett answered 23/2, 2018 at 11:0 Comment(0)
O
2

https://maven.apache.org/pom.html

The packaging type required to be pom for parent and aggregation (multi-module) projects. These types define the goals bound to a set of lifecycle stages. For example, if packaging is jar, then the package phase will execute the jar:jar goal. If the packaging is pom, the goal executed will be site:attach-descriptor

Opheliaophelie answered 8/4, 2018 at 7:42 Comment(0)
F
-1

POM(Project Object Model) is nothing but the automation script for building the project,we can write the automation script in XML, the building script files are named diffrenetly in different Automation tools

like we call build.xml in ANT,pom.xml in MAVEN

MAVEN can packages jars,wars, ears and POM which new thing to all of us

if you want check WHAT IS POM.XML

Fluent answered 15/9, 2014 at 10:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.