Wednesday, July 6, 2016

Manifest property won't write to MANIFEST.MF during packaging

Problem
I was working along happily when I realized I wanted to make some additions to the MANIFEST.MF. I had something that looked similar to this:

...
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <configuration>
        <archive>
            <manifestEntries>
                <Weblogic-Application-Version>${project.version}</Weblogic-Application-Version>
            </manifestEntries>
        </archive>
    </configuration>
</plugin>
...

Thinking that this should work. I use mvn clean package and I went to verify it's presence in my manifest only to be disappointed.

Solution
Sometimes the solution is right in front of you, and you just don't see it. Very often I am working with JAR files, however this time I was making a WAR file.

...
<packaging>war</packaging>
...

These two files use different archivers during the packaging process, so while the above <plugin> section would have been find with jar, we simply need to change a single letter, and this works just fine.

...
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
        <archive>
            <manifestEntries>
                <Weblogic-Application-Version>${project.version}</Weblogic-Application-Version>
            </manifestEntries>
        </archive>
    </configuration>
</plugin>
...

Happy coding!


No comments: