Ant <property>任务:'value'和'location'有区别吗?

Ant <property> task: is there a difference between 'value' and 'location'?

当设置 property 来引用文件路径时,使用 valuelocation 参数有区别吗?

https://ant.apache.org/manual/Tasks/property.html 的文档指出:

value 设置 属性

的值

location 将 属性 设置为给定文件的绝对文件名。

value 是否适用于一般值,而 location 仅适用于文件路径?


在现实生活中,这两行代码有区别吗?如果有,它有什么实际影响?

    <property name="cobertura.dir" value="C:/Cobertura/cobertura-1.9" />
    <property name="cobertura.dir" location="C:/Cobertura/cobertura-1.9" />

它在您已经提到的 ANT 手册中有记载...

location : Sets the property to the absolute filename of the given file. 
If the value of this attribute is an absolute path, it is left unchanged (with / and \ characters converted to the current platforms conventions). 
Otherwise it is taken as a path relative to the project's basedir and expanded.

因此您可以选择指定绝对/相对路径。

所以如果你想做相对路径,就用location。如果您使用的是绝对路径,则可以使用位置或值(互斥)

如果对其他人有帮助:

http://www.javapractices.com/topic/TopicAction.do?Id=135,作者推荐:

For properties that represent a file or directory, use the 'location' attribute, not 'value'

.properties files equate to using <property name='x' value='y'> since the 'location' attribute isn't used. This isn't recommended for files and directories, since this will not resolve relative references. If you do specify a location in a properties file, then it should be absolute, not relative. In addition, you'll need to escape backslashes.