batch updating manifest.mf for existing jars using maven

独自空忆成欢 提交于 2019-12-12 18:24:13

问题


I would like to add a custom key/value pair to the MANIFEST.MF of several existing jar files in my war project (those jars are not the project dependencies).

I already can pack/repack those jars using an ant task.

I read about "manifest" task, how can I apply that task to a fileset (if there is a way)? Thanks in advance.


回答1:


This is my first answer at StackOverflow. Hope it suits you :)

I've done it like this:

<target name="xxx.modifyManifests">
    <echo message="Modifying jar manifests to add trusted-library" />
    <apply executable="jar">
        <arg value="umf" />
        <arg line="${xxx.resources}/manifest/custom_manifest.mf" />
        <srcfile />
        <fileset dir="${xxx.target}/applets" includes="*.jar" />
    </apply>
</target>

The call is a simple one using maven-antrun-plugin:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
        <execution>
            <id>xxx.modifyManifests</id>
            <phase>compile</phase>
            <configuration>
                <target>
                    <property environment="windows" />
                    <property name="xxx.resources"
                        value="${project.build.directory}/../src/main/resources" />
                    <property name="xxx.target"
                        value="${project.build.directory}/${project.artifactId}-${project.version}" />
                    <ant antfile="${basedir}/build.xml">
                        <target name="xxx.modifyManifests" />
                    </ant>
                </target>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>

And my custom_manifest.mf is like this:

Trusted-Only: true
Trusted-Library: true


来源:https://stackoverflow.com/questions/16065570/batch-updating-manifest-mf-for-existing-jars-using-maven

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!