簡體   English   中英

螞蟻 <property> 任務:“價值”和“位置”之間有區別嗎?

[英]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.

因此,您可以選擇指定絕對/相對路徑。

因此,如果要進行相對路徑,則使用位置。 如果您要執行絕對路徑,則可以使用位置或值(互斥)

萬一它對其他人有幫助:

http://www.javapractices.com/topic/TopicAction.do?Id=135上 ,作者建議:

對於代表文件或目錄的屬性,請使用“位置”屬性,而不是“值”

.properties文件等同於使用<property name='x' value='y'>因為未使用'location'屬性。 不建議將其用於文件和目錄,因為這不會解析相對引用。 如果確實在屬性文件中指定位置,則該位置應該是絕對的,而不是相對的。 此外,您需要轉義反斜杠。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM