我有一个属性文件,我想将所有键和值传递给命令,我该怎么做?
说属性文件看起来文件
size=small
perf=true
蚂蚁任务看起来像
<exec executable="${prog}" failonerror="true">
<!-- I want to add all properties from file as argument here, -->
</exec>
这样在运行时,行为与
<exec executable="${prog}" failonerror="true">
<arg value = "size"/>
<arg value = "small"/>
<arg value = "perf"/>
<arg value = "true"/>
</exec>
我怎样才能做到这一点?谢谢
编辑:
按照 Vadzim 的建议,我现在正在使用脚本。
<property file="test.properties" prefix="testproperty"/>
<target name = "test1">
<script language="javascript"> <![CDATA[
properties = project.getUserProperties()
echo = project.createTask( "echo" );
anotation = project.getProperty("testproperty.size")
echo.setMessage(anotation);
echo.perform();
for(key in properties) {
echo.setMessage(key);
echo.perform();
echo.setMessage(properties[key]);
echo.perform();
}
]]> </script>
</target>
但是,getProperty() 正在工作,但 getProperties 仅包含诸如 notify() 之类的 java 函数
$ant test1
test1:
[echo] small
[echo] notifyAll
[echo] function notifyAll() {/*
[echo] void notifyAll()
[echo] */}
[echo] values
[echo] function values() {/*
[echo] java.util.Collection values()
[echo] */}
[echo] containsKey
[echo] function containsKey() {/*
[echo] boolean containsKey(java.lang.Object)
[echo] */}
[echo] entrySet
[echo] function entrySet() {/*
[echo] java.util.Set entrySet()
[echo] */}
[echo] keySet
[echo] function keySet() {/*
[echo] java.util.Set keySet()
[echo] */}
[echo] put
[echo] function put() {/*
[echo] java.lang.Object put(java.lang.Object,java.lang.Object)
[echo] */}
[echo] contains
[echo] function contains() {/*
[echo] boolean contains(java.lang.Object)
[echo] */}
[echo] empty
[echo] false
[echo] equals
[echo] function equals() {/*
[echo] boolean equals(java.lang.Object)
[echo] */}
[echo] notify
[echo] function notify() {/*
[echo] void notify()
[echo] */}
[echo] class
[echo] class java.util.Hashtable
[echo] elements
[echo] function elements() {/*
[echo] java.util.Enumeration elements()
[echo] */}
[echo] keys
[echo] function keys() {/*
[echo] java.util.Enumeration keys()
[echo] */}
[echo] isEmpty
[echo] function isEmpty() {/*
[echo] boolean isEmpty()
[echo] */}
[echo] size
[echo] function size() {/*
[echo] int size()
[echo] */}
[echo] putAll
[echo] function putAll() {/*
[echo] void putAll(java.util.Map)
[echo] */}
[echo] clear
[echo] function clear() {/*
[echo] void clear()
[echo] */}
[echo] wait
[echo] function wait() {/*
[echo] void wait()
[echo] void wait(long)
[echo] void wait(long,int)
[echo] */}
[echo] containsValue
[echo] function containsValue() {/*
[echo] boolean containsValue(java.lang.Object)
[echo] */}
[echo] toString
[echo] function toString() {/*
[echo] java.lang.String toString()
[echo] */}
[echo] hashCode
[echo] function hashCode() {/*
[echo] int hashCode()
[echo] */}
[echo] clone
[echo] function clone() {/*
[echo] java.lang.Object clone()
[echo] */}
[echo] get
[echo] function get() {/*
[echo] java.lang.Object get(java.lang.Object)
[echo] */}
[echo] getClass
[echo] function getClass() {/*
[echo] java.lang.Class getClass()
[echo] */}
[echo] remove
[echo] function remove() {/*
[echo] java.lang.Object remove(java.lang.Object)
[echo] */}
BUILD SUCCESSFUL
Total time: 0 seconds
迭代 getProperties() 结果的正确方法是什么?
非常感谢任何建议
编辑2:
jbeard4在这里有一个很好的解释。关于javascript问题。所以正确的方法是
<script language="javascript"> <![CDATA[
properties = project.getUserProperties()
var keyIter = properties.keySet().iterator();
while(keyIter.hasNext()) {
var key = keyIter.next();
var value = properties.get(key);
echo.setMessage(key+value);
echo.perform();
}
]]> </script>