Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to control the pom.xml inside jar built by maven?

When maven builds a jar it places a pom.xml at META-INF///pom.xml. This is the original pom of the artifact. No variables are expanded or inherited and no inherited dependencies are listed. This makes the information of the production jar dependent on the build environment.

How can the pom inside the jar be configured ? Best would be some configuration of the maven-jar-plugin.

like image 961
openCage Avatar asked Dec 14 '10 09:12

openCage


People also ask

Does jar file contains POM xml?

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.

What is POM xml in jar file?

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.

How do I use Maven in POM xml?

xml. The POM contains information about the project and various configuration detail used by Maven to build the project(s). Before creating a POM, we should first decide the project group (groupId), its name (artifactId) and its version as these attributes help in uniquely identifying the project in repository.


1 Answers

I had a similar requirement, as I wanted to get all the information that belongs to the parent pom.xml. In others words, I wanted to have, in addition to the "raw" pom.xml, the effective pom inside the JAR generated.

The idea is to use the help:effective-pom plugin and goal during the generation of the JAR, and put it with the pom.xml. This is done with this configuration:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-help-plugin</artifactId>
    <version>2.1.1</version>
    <executions>
        <execution>
            <phase>generate-resources</phase>
            <goals>
                <goal>effective-pom</goal>
            </goals>
            <configuration>
                <output>${project.build.outputDirectory}/META-INF/maven/${project.groupId}/${project.artifactId}/effective-pom.xml</output>
            </configuration>
        </execution>
    </executions>
</plugin>

(source)

like image 179
Romain Linsolas Avatar answered Oct 23 '22 18:10

Romain Linsolas