What is the purpose of the pom.xml inside a jar's META-INF folder?
Asked Answered
F

3

5

Typically, a maven built jar artifact will have it's pom included under META-INF. I recently noticed that the Spring jars don't have this. So, that causes me to wonder about the purpose of that pom.

It seems like maven retrieves the pom directly from the repository when it's doing things that require knowledge of the artifacts meta-data, e.g. when determining dependencies.

So, what's the embedded one for?

Fluke answered 8/2, 2013 at 16:31 Comment(1)
H
5

The Maven docs suggest two reasons for the pom in this location.

1) Merely for reference, as a convenience. As the docs say, it makes the artifact "self describing"

2) You can get at this information from within your application using Java. This enables the arfiact to auto-report it's version within the application.

Haitian answered 8/2, 2013 at 16:47 Comment(1)
I am adding <outputDirectory> attribute in the jar plugin to specify the location of jar file. But at that location maven is not exporting pom.xml file which is used in generating the jar. Can you please tell me how to export the pom.xml too in the same location other then the copy plugin.Jannajannel
D
3

The pom you will find in the repository is not necessarily the one used to build the artifact. It is aimed at the users of the artifact and can be customized when building your artifact.

The one included inside the artifact IS the one used to produce the artifact. There are options to not have it included in the artifact.

Demiurge answered 8/2, 2013 at 16:49 Comment(2)
what is the option "not to have it in the meta-inf" please ?Pase
ok i reply to myself :-) : <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <addMavenDescriptor>false</addMavenDescriptor> </archive> </configuration> </plugin>Pase
P
0

I don't know if this's a use for it, when I build and upload an artifact to repository, I can remove all it's dependencies in artifact's pom.xml for maven repository, and the origin pom will be META-INF/../pom.xml.

In this situation, when my SpringBoot project import this artifact as a dependency, maven won't actively download it's dependencies, which will make SpringBoot jar smaller.

Pathogen answered 30/10 at 3:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.