简体   繁体   English

为什么不能使用maven-war-plugin将密钥与“ WEB-INF / classes / META-INF / MANIFEST.MF”合并?

[英]Why keys are not merged with “WEB-INF/classes/META-INF/MANIFEST.MF” using maven-war-plugin?

I am building an application and then merging some custom keys in the MANIFEST.MF file: 我正在构建一个应用程序,然后在MANIFEST.MF文件中合并一些自定义键:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-war-plugin</artifactId>
  <version>2.5</version>
  <configuration>
    <archive>
      <manifestEntries>
        <Build-Time>${maven.build.timestamp}</Build-Time>
        <Build-Revision>${buildNumber}</Build-Revision>
      </manifestEntries>
    </archive>
  </configuration>
</plugin>

I have 2 profiles, the production profile uses the following resource config: 我有2个配置文件,生产配置文件使用以下资源配置:

<resources>
    <resource>
        <!-- "all" is used for all profiles, "development" and "production" -->
        <directory>src/main/resources/all</directory>
    </resource>
    <resource>
        <!-- "prod" is just used for "production" -->
        <directory>src/main/resources/prod</directory>
    </resource>
</resources>

A default MANIFEST.MF is located at src/main/resources/all/META-INF/MANIFEST.MF , which should be used as a base. 默认的MANIFEST.MF位于src/main/resources/all/META-INF/MANIFEST.MF ,应将其用作基础。

What do I expect? 我期望什么?

I expect that the MANIFEST.MF is available at myproject.war/WEB-INF/classes/META-INF/MANIFEST.MF with "Build-Time" and "Build-Revision" updated according to the values provided. 我希望MANIFEST.MF在myproject.war/WEB-INF/classes/META-INF/MANIFEST.MF可用,并且根据提供的值更新了“构建时间”和“构建修订”。 Then I will be able to access the MANIFEST.MF file at runtime to retrieve the "Build-Revision" key and handle caching stuff. 然后,我将能够在运行时访问MANIFEST.MF文件,以检索“ Build-Revision”键并处理缓存内容。

What happens instead? 会发生什么呢?

What happens instead is that the MANIFEST.MF is created inside myproject.war/META-INF/MANIFEST.MF with the values updated, and in the WEB-INF location there is just a copy of the MANIFEST.MF without any key updated. 相反,发生的情况是在myproject.war/META-INF/MANIFEST.MF内创建了MANIFEST.MF,并更新了值,并且在WEB-INF位置仅存在MANIFEST.MF的副本,而未更新任何密钥。

Why does WEB-INF/classes/META-INF/MANIFEST.MF is not updated through maven-war-plugin? 为什么未通过maven-war-plugin更新WEB-INF / classes / META-INF / MANIFEST.MF?

(I figured it out, it was my ignorance of how maven handles src/main/resources and the manifest file) (我想通了,这是我对Maven如何处理src/main/resources和manifest文件的无知)

Maven creates a proper MANIFEST.MF file inside META-INF/ and uses it as the default convention path for a manifest, there is no need to create another one inside the src/main/resources folder, the default should be in the root. Maven在META-INF/创建一个正确的MANIFEST.MF文件,并将其用作清单的默认约定路径,无需在src/main/resources文件夹中创建另一个文件,默认文件应位于根目录中。

If you remove the MANIFEST from src/main/resources (which would be copied to WEB-INF/classes/META-INF/MANIFEST.MF ) you will have only one and will be able to access the META-INF/MANIFEST.MF from the application using: 如果从src/main/resources删除MANIFEST(将复制到WEB-INF/classes/META-INF/MANIFEST.MF ),则只有一个,并且可以访问META-INF/MANIFEST.MF从应用程序中使用:

request.getServletContext().getResourceAsStream( "/META-INF/MANIFEST.MF" );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM