kulatamicuda
kulatamicuda

Reputation: 1661

Maven plugin to manipulate existing jar

I already have maven build pom (slightly complicated) which creates compiled and prepared jar file for my project. I copy that file to various destinations using maven-antrun-plugin by using copy in targets section.

What I want to achieve is to change manifest file (add something to it) in each copy. For example:

prepared.jar -- copy to --> /linux/prepared-linux.jar (the same content as prepared.jar, but the manifest contains something specific to linux)

prepared.jar -- copy to --> /win64/prepared-win64.jar (the same content as prepared.jar, but the manifest contains something specific to windows)

I do not want to create prepared.jar multiple times, just to copy it and change manifest in copy. Does anybody know about some maven 3.1 compatible plugin which is capable to do it and which is easily configurable and works on windows and linux platforms ?

Upvotes: 1

Views: 2117

Answers (2)

Master Slave
Master Slave

Reputation: 28569

Posting an alternative just for the sake of info, hope you don't mind. Basically you can achieve the same by using maven-jar-plugin with multiple executions, something like

<plugin>
    <artifactId>maven-jar-plugin</artifactId>
    <executions>
        <execution>
            <id>only-library</id>
            <goals>
                <goal>jar</goal>
            </goals>
            <phase>package</phase>
        </execution>
        <execution>
            <id>linux</id>
            <goals>
                <goal>jar</goal>
            </goals>
            <phase>package</phase>
            <configuration>
                <classifier>linux</classifier>
                <archive>
                    <index>true</index>
                    <manifest>
                        <addClasspath>true</addClasspath>
                    </manifest>
                    <manifestEntries>
                        <yourKey>linux</yourKey>
                    </manifestEntries>
                </archive>
            </configuration>
        </execution>
        <execution>
            <id>win64</id>
            <goals>
                <goal>jar</goal>
            </goals>
            <phase>package</phase>
            <configuration>
                <classifier>win64</classifier>
                <archive>
                    <index>true</index>
                    <manifest>
                        <addClasspath>true</addClasspath>
                    </manifest>
                    <manifestEntries>
                        <yourKey>win64</yourKey>
                    </manifestEntries>
                </archive>
            </configuration>
        </execution>
    </executions>
</plugin>

Upvotes: 3

kulatamicuda
kulatamicuda

Reputation: 1661

So finally I was able to solve it myself based on comment from @RC. and by looking here Simpliest way to add an attribute to a jar Manifest in Maven the solution was to add something like to my pom file after the copy element:

        <jar file="${install.dir}/linux/${program.name}.jar" update="true">
          <manifest>
            <attribute name="my specific linux att" value="my specific linux value" />
          </manifest>
        </jar>                                                

Upvotes: 2

Related Questions