[英]Ant <property> task: is there a difference between 'value' and 'location'?
When setting a property
to refer to a filepath, is there a difference between using the value
or location
parameters? 将
property
设置为引用文件路径时,使用value
或location
参数之间有区别吗?
The documentation at https://ant.apache.org/manual/Tasks/property.html states that: https://ant.apache.org/manual/Tasks/property.html上的文档指出:
value
sets the value of the property value
设置属性的值
location
sets the property to the absolute filename of the given file. location
将属性设置为给定文件的绝对文件名。
So is value
for general values, and location
just for filepaths? 那么,
value
一般价值观, location
只是文件路径?
In a real life example, is there a difference between these two lines of code? 在现实生活中的示例中,这两行代码之间有区别吗? If so, what actual impact does it have?
如果是这样,它将产生什么实际影响?
<property name="cobertura.dir" value="C:/Cobertura/cobertura-1.9" />
<property name="cobertura.dir" location="C:/Cobertura/cobertura-1.9" />
It is documented in the ANT manual you have already referred... 您已经参考过的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.
So you have the option of specifying an absolute/ relative path. 因此,您可以选择指定绝对/相对路径。
So location is used if you want to do relative paths. 因此,如果要进行相对路径,则使用位置。 Either location or value (mutually exclusive) can be used if you're doing absolute paths
如果您要执行绝对路径,则可以使用位置或值(互斥)
In case it helps anyone else: 万一它对其他人有帮助:
At http://www.javapractices.com/topic/TopicAction.do?Id=135 , the writer recommends: 在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..properties文件等同于使用
<property name='x' value='y'>
因为未使用'location'属性。 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.
此外,您需要转义反斜杠。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.