建立一個 manifest 檔案。
這個任務可用於撰寫 Manifest 檔案,並選擇性地取代或更新現有的檔案。
Manifest 根據 Jar 檔案規格 進行處理。具體來說,manifest 元素包含一組屬性和區段。這些區段反過來可能包含屬性。特別注意,這可能會導致大於 72 位元的 manifest 行被換行並延續到下一行。
Apache Ant 團隊經常收到抱怨,表示這個任務會產生無效的 manifest。總體而言,並非如此:我們相信我們完全遵循規格。常見的問題是,某些第三方 manifest 閱讀器並未像他們認為的那樣遵循相同的規格;我們無法僅因為一個應用程式損壞就產生無效的 manifest 檔案。Java ME 執行時期似乎特別麻煩。
如果您發現 Ant 產生的 manifest 與您的執行時期不相容,請取得它建立的 manifest,根據需要修正它,並改用 zip 任務來建立 JAR,並提供手工製作的 manifest。
屬性 | 說明 | 必要 |
---|---|---|
file | 要建立/更新的 manifest 檔案。 | 是 |
mode | update或 replace之一。 |
否;預設為 replace |
encoding | 更新時用於讀取現有 manifest 的編碼。此任務在撰寫 manifest 時將始終使用 UTF-8。 | 否;預設為 UTF-8 編碼 |
mergeClassPathAttributes | 是否合併在不同 manifest 中找到的 Class-Path 屬性(如果更新)。如果為 false,則只會保留最新 manifest 的屬性。自 Ant 1.8.0 起。 除非您也將 flattenAttributes 設定為 true,否則這可能會導致 manifest 包含多個 Class-Path 屬性,這會違反 manifest 規格。 |
否;預設為 false |
flattenAttributes | 是否將在區段中出現多次的屬性(這只會發生在 Class-Path 屬性)合併成單一屬性。自 Ant 1.8.0 起。 |
否;預設為 false |
manifest 檔案的一個屬性。未巢狀到區段中的那些屬性將會新增到主區段。
屬性 | 說明 | 必要 |
---|---|---|
name | 屬性的名稱,必須符合正規表示式 [A-Za-z0-9][A-Za-z0-9-_]*。 |
是 |
value | 屬性的值。 | 是 |
一個明細區段—你可以將 屬性 元素巢狀到區段中。
屬性 | 說明 | 必要 |
---|---|---|
name | 區段的名稱。 | 否,預設為主要區段 |
建立或取代檔案 MANIFEST.MF。請注意,Built-By
屬性將採用 Ant 屬性 ${user.name}
的值。${version}
和 ${TODAY}
屬性也是如此。此範例會產生一個 MANIFEST.MF,其中包含 封裝版本識別,供封裝 common 使用。
<manifest file="MANIFEST.MF"> <attribute name="Built-By" value="${user.name}"/> <section name="common"> <attribute name="Specification-Title" value="Example"/> <attribute name="Specification-Version" value="${version}"/> <attribute name="Specification-Vendor" value="Example Organization"/> <attribute name="Implementation-Title" value="common"/> <attribute name="Implementation-Version" value="${version} ${TODAY}"/> <attribute name="Implementation-Vendor" value="Example Corp."/> </section> <section name="common/class1.class"> <attribute name="Sealed" value="false"/> </section> </manifest>
上述明細產生的明細看起來會像這樣
Manifest-Version: 1.0 Built-By: bodewig Created-By: Apache Ant 1.9 Name: common Specification-Title: Example Specification-Vendor: Example Organization Implementation-Vendor: Example Corp. Specification-Version: 1.2 Implementation-Version: 1.2 September 10, 2013 Implementation-Title: common Name: common/class1.class Sealed: false