Ant任务:读取和用户清单实现版本

时间:2016-09-20 22:51:13

标签: java ant version manifest

我对ant任务很新,到目前为止我设法用一些args调用一个exec,现在我正在尝试从META-IF/MANIFEST.MF文件读取一个版本来调用一个带有{的exec {1}}此文件的属性为arg(这是为我的项目创建版本化设置)。 到目前为止,我只能找到如何替换属性或如何从jar文件中读取,但永远不会从Implementation-Version文件中读取并使用read属性作为var以便稍后在ant任务中使用! 在此先感谢:)

1 个答案:

答案 0 :(得分:1)

您可以使用loadfile任务,嵌套FilterChain s:

<loadfile property="implementation.version" srcFile="MANIFEST.MF">
    <filterchain>
        <!-- following filter tokenize input file and return only
             the lines that match the pattern. Matched string is 
             replaced by an empty string to get only the value of the
             manifest property.
        -->
        <tokenfilter>
            <containsregex pattern="Implementation-Version:[ \t]*" replace="" flags="i"/>
        </tokenfilter>
    </filterchain>
</loadfile>
<!-- now 'implementation.version' contains the rest of the line that was matching the regex -->
<echo>Implementation version is ${implementation.version}</echo>