Fagner Brack
Fagner Brack

Reputation: 2403

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:

<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:

<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.

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. Then I will be able to access the MANIFEST.MF file at runtime to retrieve the "Build-Revision" key and handle caching stuff.

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.

Why does WEB-INF/classes/META-INF/MANIFEST.MF is not updated through maven-war-plugin?

Upvotes: 0

Views: 670

Answers (1)

Fagner Brack
Fagner Brack

Reputation: 2403

(I figured it out, it was my ignorance of how maven handles src/main/resources and the manifest file)

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.

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:

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

Upvotes: 1

Related Questions