假设我有一个文件test.key,并且该文件包含一个字符串,我们称其为“ 123456789”。如何将此文件作为参数传递给ant build中的程序?我不知道这样的事情可能吗?ant -Darg ='cat test.key'
其中cat test.key是Linux终端上的命令。
您可以使用LoadFile ant任务,该任务将文件的内容读入属性:https://ant.apache.org/manual/Tasks/loadfile.html
<loadfile property="arg.value"
srcFile="test.key"
failonerror="false"/>
然后,您可以在具有以下属性的exec任务中使用此属性:https://ant.apache.org/manual/Tasks/exec.html
<exec executable="myprogram">
<arg value="${arg.value}"/>
</exec>
为了增加灵活性,您可以将文件名作为属性传递:
ant -Dfile.name=test.key
因此,LoadFile任务变为:
<loadfile property="arg.value"
srcFile="${file.name}"
failonerror="false"/>