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

2

25

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.

Area answered 5/11, 2009 at 2:41 Comment(0)
I
27

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.

Intimist answered 5/11, 2009 at 3:18 Comment(2)
"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" - can you give me examples on why my app would need the metadata in a pom file ?Underthrust
for example when you don't want to publish the jar to an online mvn repo, you can give the jar file alone to someone else, and they can install to their local mvn repo using mvn-install-plugin:3.0.0-M1 and use it. maven would know the correct dependencies of this locally-installed jar, which is not possible without the pom.xml.Statuary
R
5

The pom.xml inside JAR is designed for following purposes,

  1. Automatic dependency resolution.
  2. Deployment of JAR. It's possible to extract pom.xml from JAR automatically.
  3. Integrity check by repository (JAR matches POM).

I don't know if any of these features are implemented anywhere. You can ignore it for sure.

Rumpus answered 5/11, 2009 at 2:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.