Ant字符串比较

时间:2011-09-14 07:47:13

标签: ant

我在ant中有一个脚本,我需要按字典顺序比较2个字符串。 类似的东西:

 "1.2.3".compareTo("1.2.4")

我找不到办法这样做......有什么想法吗?我正在使用ant 1.8和ant-contrib。

由于

1 个答案:

答案 0 :(得分:4)

要使此解决方案正常工作,您需要将JAVA_HOME指向JRE 1.6或更高版本。

<project name="test" default="test">
<scriptdef name="compare" language="javascript">
     <attribute name="lhs" />
     <attribute name="rhs" />
     <attribute name="property" />
     <![CDATA[
       var lhs = attributes.get("lhs");
       var rhs = attributes.get("rhs");
       project.setProperty(attributes.get("property"), lhs > rhs);
     ]]>
</scriptdef>

<target name="test">
    <compare lhs="1.2.3" rhs="1.2.4" property="result"/>
    <echo message="Result is : ${result}"/>
</target>
</project>

输出:

test:
 [echo] Result is : false
相关问题