自动添加多个"部分"到清单?

Phi*_*ham 6 java ant manifest

我正在使用ant来生成MANIFEST.MF.jar,我需要<section>根据目录中的文件列表添加多个清单块.但是,我需要在构建时自动执行此过程,因为列表将在开发和部署之间发生变化.

例如:

<manifest file="MANIFEST.MF">
  <foreach files="./*">
    <section name="section">
      <attribute name="Attribute-Name" value="$file"/>
    </section>
  </foreach>
</manifest>
Run Code Online (Sandbox Code Playgroud)

foreach从Ant-contrib 看过,但看起来它不会在这个实例中起作用.

这可能吗?

Col*_*ert 4

您可以通过清单任务来完成此操作

<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>
Run Code Online (Sandbox Code Playgroud)

它将生成这个清单:

清单版本:1.0
创建者:Apache Ant 1.7

名称:部分
属性名称:值

名称:section/class1.class
第二个属性名称:otherValue

您可以维护两个不同的自定义任务来处理不同的情况,并在正确的时刻调用正确的任务。


对于“自动”管理:

<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>
Run Code Online (Sandbox Code Playgroud)