我有一个 ant 任务,它读取环境属性
myproject.properties
。环境属性值设置为
prod
并显示“Prod 条件为真”。我看到
${environment}
变量设置为 prod,但 if 条件永远不为 true。能
有人解释一下为什么吗?
我的项目.属性:
environment=prod
构建.xml:
<project name="my-project" default="run" basedir=".">
<property file="myproject.properties" />
<target name="run">
<echo message="running target run ${environment}"/>
<if>
<equals arg1="${environment}" arg2="prod">
<then>
<echo message="Prod condition is true"/>
<!--do prod environment specific task-->
</then>
</if>
</target>
</project>
最佳答案
除了您的 equals
任务缺少结束标签(实际上它应该是一个自关闭标签),我敢打赌你有一个隐藏在某处的空白。在你的echo
,用撇号或其他内容将属性的打印输出括起来:
<echo message="running target run '${environment}'"/>
您可能会在值的末尾看到一个空格。这是我能想到的唯一合理的解释。或者,尝试使用 -Denvironment=prod
运行看看会发生什么。
关于java - ant 如果目标失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12699067/