Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the significance of the POM file that Maven places in a JAR file, is it used by anything?

Tags:

When Maven builds a JAR file, it places the module's POM file inside (seemingly in the directory <groupid>/<artifactid>).

When I build a JAR file from Ant to be deployed via the Maven Ant tasks, is the presence of this POM file (the one inside the JAR) important? It doesn't seem to be, but I just wanted to be sure that it is not being used anywhere, and to confirm where exactly in the JAR file it is supposed to be.

like image 817
Dan Dyer Avatar asked Nov 05 '09 02:11

Dan Dyer


People also ask

What is the significance of POM?

A Project Object Model or POM is the fundamental unit of work in Maven. It is an XML file that contains information about the project and configuration details used by Maven to build the project. It contains default values for most projects.

Where is POM in jar?

The pom file, located in the archive in META-INF/maven/${groupId}/${artifactId}/pom. xml.

Where is the POM file located in the Maven project?

The POM file is named pom. xml and should be located in the root directory of your project.


1 Answers

The pom.xml and pom.properties files are packaged up in the JAR so that each artifact produced by Maven is self-describing and also allows you to utilize the metadata in your own application, should the need arise. One simple use might be to retrieve the version of your application.

That said, the inclusion of these files can be deactivated if desired through MavenArchiverConfiguration which admits a boolean addMavenDescriptor parameter and it's safe to not include them (even if I find it nice to have them). For example for a JAR:

<project>   ...   <build>     <plugins>       <plugin>         <groupId>org.apache.maven.plugins</groupId>         <artifactId>maven-jar-plugin</artifactId>         <configuration>           <archive>             <addMavenDescriptor>false</addMavenDescriptor>           </archive>         </configuration>       </plugin>     </plugins>     ...   </build>   ... </project> 

Regarding the location of these files, the documentation of addMavenDescriptor says:

Whether the generated archive will contain these two Maven files:

  • The pom file, located in the archive in META-INF/maven/${groupId}/${artifactId}/pom.xml
  • A pom.properties file, located in the archive in META-INF/maven/${groupId}/${artifactId}/pom.properties

The default value is true.

This should answer your question.

like image 64
Pascal Thivent Avatar answered Nov 08 '22 09:11

Pascal Thivent