Maven放置在JAR文件中的POM文件的重要性是什么,它是否被任何东西使用? [英] What is the significance of the POM file that Maven places in a JAR file, is it used by anything?

查看:706
本文介绍了Maven放置在JAR文件中的POM文件的重要性是什么,它是否被任何东西使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当Maven构建一个JAR文件时,它将模块的POM文件放在里面(看似在目录< groupid> /< artifactid>)。

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

当我从Ant构建一个JAR文件,通过Maven Ant任务进行部署,这个POM文件(JAR内部的文件)的存在是否重要?它似乎不是,但我只是想确保它没有在任何地方使用,并确认它应该在JAR文件中的确切位置。

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.

推荐答案

打包 pom.xml pom.properties 文件在JAR中,以便Maven生成的每个工件都是自我描述的,并且还允许您在需要时利用自己应用程序中的元数据。一个简单的用途可能是检索应用程序的版本。

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.

也就是说,如果需要,可以通过允许布尔值的MavenArchiverConfiguration停用这些文件 addMavenDescriptor 参数并且不包含它们是安全的(即使我觉得很好用它们)。例如,对于JAR:

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>

关于这些文件的位置, addMavenDescriptor 说:

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


是否生成的存档将包含这两个Maven文件:

Whether the generated archive will contain these two Maven files:


  • pom文件,位于 META-INF /中的存档中maven / $ {groupId} / $ {artifactId} /pom.xml

  • A pom.properties 文件,位于 META-INF / maven / $ {groupId} / $ {artifactId} /pom.properties

  • 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

默认值是true。

这应该回答你的问题。

这篇关于Maven放置在JAR文件中的POM文件的重要性是什么,它是否被任何东西使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆