是否可以替换Ant的build.xml中的属性中的文本?

evg*_*iuz 3 java ant

我有一个属性app.version,设置为1.2.0(当然,总是在变化),需要创建名为"something-ver-1_2_0"的zip文件.这可能吗?

Mad*_*sen 7

您可以使用pathconvert任务替换"." 使用"_"并分配给新属性:

<?xml version="1.0" encoding="UTF-8"?>
<project>
    <property name="app.version" value="1.2.0"/>

    <pathconvert property="app.version.underscore" dirsep="" pathsep="" description="Replace '.' with '_' and assign value to new property">
        <path path="${app.version}" description="Original app version with dot notation" />

        <!--Pathconvert will try to add the root directory to the "path", so replace with empty string -->
        <map from="${basedir}" to="" />

        <filtermapper>
            <replacestring from="." to="_"/>     
        </filtermapper>

    </pathconvert>

    <echo>${app.version} converted to ${app.version.underscore}</echo>
</project>
Run Code Online (Sandbox Code Playgroud)