Ant 任务:读取和用户清单实现版本
Ant task : read and user manifest implementation version
我对 ant 任务还很陌生,到目前为止,我已经设法用一些参数调用一个 exec,现在我正在尝试从 META-IF/MANIFEST.MF
文件中读取一个版本来调用一个 exec该文件的 Implementation-Version
属性 作为参数(这意味着为我的项目创建版本化设置)。
到目前为止,我只能找到如何替换属性或如何从 jar 文件中读取,但从来没有从 MANIFEST.MF
文件中找到并将读取的 属性 用作稍后在 ant 任务中的 var!
提前致谢:)
您可以使用 loadfile task, with nested FilterChains :
<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>
我对 ant 任务还很陌生,到目前为止,我已经设法用一些参数调用一个 exec,现在我正在尝试从 META-IF/MANIFEST.MF
文件中读取一个版本来调用一个 exec该文件的 Implementation-Version
属性 作为参数(这意味着为我的项目创建版本化设置)。
到目前为止,我只能找到如何替换属性或如何从 jar 文件中读取,但从来没有从 MANIFEST.MF
文件中找到并将读取的 属性 用作稍后在 ant 任务中的 var!
提前致谢:)
您可以使用 loadfile task, with nested FilterChains :
<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>