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

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

问题描述

当 Maven 构建 JAR 文件时,它会将模块的 POM 文件放入其中(似乎在目录 / 中).

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

当我从 Ant 构建要通过 Maven Ant 任务部署的 JAR 文件时,这个 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.xmlpom.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
  • 的存档中

默认值为真.

这应该可以回答您的问题.

This should answer your question.

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

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