1

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 ?

kulatamicuda
  • 1,603
  • 2
  • 21
  • 40
  • 1
    "using maven-antrun-plugin", then you can probably use your ant script to alter the manifest. –  Jan 08 '15 at 12:31
  • @RC. I am using antrun but only to copy by element. Do not know how to alter jar file using ant or how to create ant script at all. – kulatamicuda Jan 08 '15 at 12:38
  • @RC. thanks and +1, I was able to solve it myself after you pointed me where to look at :) – kulatamicuda Jan 08 '15 at 13:10

2 Answers2

2

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>                                                
Community
  • 1
  • 1
kulatamicuda
  • 1,603
  • 2
  • 21
  • 40
2

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>
Master Slave
  • 27,771
  • 4
  • 57
  • 55