【问题标题】:Ant task : read and user manifest implementation versionAnt任务:读取和用户清单实现版本
【发布时间】:2017-01-29 00:24:34
【问题描述】:
我对 ant 任务很陌生,到目前为止我已经设法用一些 args 调用了一个 exec,现在我正在尝试从 META-IF/MANIFEST.MF 文件中读取一个版本来调用一个带有 Implementation-Version 的 exec此文件的属性作为 arg(这是为了为我的项目创建版本化设置)。
到目前为止,我只能找到如何替换属性或如何从 jar 文件中读取,但永远不会从 MANIFEST.MF 文件中找到,并将读取属性用作稍后在 ant 任务中的 var!
在此先感谢:)
【问题讨论】:
标签:
java
ant
version
manifest
【解决方案1】:
您可以使用loadfile 任务,嵌套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>