I'm using ant to generate the MANIFEST.MF
for a .jar, and I need to add multiple manifest <section>
blocks based on a list of files in a directory. However, I need to automate the process to do this at build-time since the list will change between development and deployment.
For example:
<manifest file="MANIFEST.MF">
<foreach files="./*">
<section name="section">
<attribute name="Attribute-Name" value="$file"/>
</section>
</foreach>
</manifest>
I've looked at foreach
from Ant-contrib but it doesn't look like it will work in this instance.
Is this possible?
You can do this with the Manifest task
<manifest file="MANIFEST.MF">
<section name="section">
<attribute name="Attribute-Name" value="value"/>
</section>
<section name="section/class1.class">
<attribute name="Second-Attribute-Name" value="otherValue"/>
</section>
</manifest>
It will generate this manifest :
Manifest-Version: 1.0
Created-By: Apache Ant 1.7Name: section
Attribute-Name: valueName: section/class1.class
Second-Attribute-Name: otherValue
You can maintain two different custom tasks to handle the different cases, and call the right one at the right moment.
For an "automatic" management :
<target name="manifest-generation">
<foreach param="file" target="manifest">
<path>
<fileset dir=".">
<include name="**/*.class"/>
</fileset>
</path>
</foreach>
</target>
<target name="manifest">
<manifest file="MANIFEST.MF" mode="update">
<section name="${file}">
<attribute name="Attribute-Name" value="value"/>
</section>
</manifest>
</target>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With