java - Ant 任务: read and user manifest implementation version

标签 java ant version manifest

我对 ant 任务还很陌生,到目前为止,我已经成功地使用一些参数调用了 exec,现在我正在尝试从 META-IF/MANIFEST.MF 中读取版本> 文件来调用 exec,并使用该文件的 Implementation-Version 属性作为参数(这意味着为我的项目创建版本化设置)。 到目前为止,我只能找到如何替换属性或如何从 jar 文件中读取,但从未从 MANIFEST.MF 文件中找到并将读取的属性用作稍后在 ant 任务中的 var! 预先感谢:)

最佳答案

您可以使用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>

关于java - Ant 任务: read and user manifest implementation version,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39604915/

相关文章:

java - H2 数据库 org.h2.Driver ClassNotFoundException

运行 ant.bat 时出现 ant 错误 "The syntax of the command is incorrect."

java - 关于java中ADT树的问题

java - POI条形图生成一系列有问题

java - ant exec 任务错误,代码=3

Clang OpenMP 版本,无法获取最新版本

ios - 应用程序颠覆 float

python - 在 azureml 镜像中指定 python 版本

java - 尝试返回数组中的单个元素时,如何在for循环中修复 “missing return statement”?

java - 如何让 vaadin 组件同时选择日期和时间