LoadProperties

說明

將檔案內容載入為 Apache Ant 屬性。這等同於 <property file|resource=.../>,但它支援巢狀的 <filterchain> 元素。此外,如果檔案不存在,則會以錯誤中止建置,而不是印出警告。

注意:此任務的 prefixValues 屬性的預設值與 <property> 任務中同一個屬性的預設值不同。

參數

屬性 說明 必要
srcFile 來源檔案 下列其中一個或巢狀資源
resource 屬性檔案的資源名稱
encoding 載入檔案時要使用的編碼
classpath 尋找資源時要使用的類別路徑。
classpathref 尋找資源時要使用的類別路徑,以 參考 在其他地方定義的 <path> 提供。
prefix 套用至載入屬性的前置詞。自 Ant 1.8.1 起 否;預設為 .
prefixValues 擴充屬性的右側時,是否套用前置詞。自 Ant 1.8.2 起 否;預設為 true

指定為巢狀元素的參數

任何 資源 或單一元素資源集合

自 Ant 1.7 起

指定的資源將用作 srcFileresource

FilterChain

classpath

resource 屬性搭配使用。

範例

file.properties 的內容載入為 Ant 屬性。

<loadproperties srcFile="file.properties"/>

<loadproperties>
    <file file="file.properties"/>
</loadproperties>

從檔案 file.properties 中讀取包含字串 import. 的行,並將它們載入為 Ant 屬性。

<loadproperties srcFile="file.properties">
    <filterchain>
        <linecontains>
            <contains value="import."/>
        </linecontains>
    </filterchain>
</loadproperties>

載入 https://example.org/url.properties.gz 的內容,即時解壓縮,並將內容載入為 Ant 屬性。

<loadproperties>
    <gzipresource>
        <url url="https://example.org/url.properties.gz"/>
    </gzipresource>
</loadproperties>