我有一个在Ant中的脚本,需要对两个字符串进行字典序比较。类似于:
"1.2.3".compareTo("1.2.4")
我找不到方法来实现这个...有什么想法吗?我正在使用ant 1.8和ant-contrib。
谢谢。
我有一个在Ant中的脚本,需要对两个字符串进行字典序比较。类似于:
"1.2.3".compareTo("1.2.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