When setting a property
to refer to a filepath, is there a difference between using the value
or location
parameters?
The documentation at https://ant.apache.org/manual/Tasks/property.html states that:
value
sets the value of the property
location
sets the property to the absolute filename of the given file.
So is value
for general values, and location
just for filepaths?
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...
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:
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.