gpt4 book ai didi

ant - 如果值为空,如何在 Ant 中省略 list 属性?

转载 作者:行者123 更新时间:2023-12-02 04:43:37 24 4
gpt4 key购买 nike

这在 Ant 中定义了一个 list :

<manifest>
<attribute name="Main-Class" value="${main-class}"/>
</manifest>

当属性包含一个空字符串时,如何在 list 中省略一个空的主类条目?

最佳答案

唯一干净的解决方案是编写两次 ant 任务:有和没有 list 。

但是如果你不想这样做,你可以使用下面的技巧。创建两个 list 文件:一个有主类,一个没有。第一个 list 中的主类应替换为占位符(标记)(例如 @main-class@)。然后你可以做

<condition
property="manifest-file"
value="manifest-without-main-class.mf"
else="manifest-with-main-class.mf"
>
<length string="${main-class}" trim="true" length="0" />
</condition>

<copy file="manifest-template.mf" tofile="manifest-with-main-class.mf"/>
<replace
file="manifest-with-main-class.mf"
token="@main-class@"
value="${manifest-file}"
/>

<jar manifest="${manifest-file}" ...>
...
</jar>

使用manifest-template.mf:

Manifest-Version: 1.0
Created-By: ...
Built-By: ...
Main-Class: @main-class@

manifest-without-main-class.mf:

Manifest-Version: 1.0
Created-By: ...
Built-By: ...

关于ant - 如果值为空,如何在 Ant 中省略 list 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20283518/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com