此任務已棄用。請改用 zipfileset 或 zipgroupfileset 搭配 Jar 任務 或 Zip 任務。如需基於 JDK 的 jlink 工具的任務,請參閱 Link。
如需基於 JDK 的 jlink 工具的任務,請參閱 Link。此任務完全是為了其他目的而設計。
連結子建置和函式庫中的項目。
jlink
任務可與 jar
任務類似地用於建置 jar 和 zip 檔案。不過,jlink
提供了控制輸入檔案中的項目新增至輸出檔案方式的選項。特別是,它提供了合併多個 zip 或 jar 檔案中項目的功能。
如果直接指定合併檔案(例如,在 mergefiles
路徑元素的最上層),而且 合併檔案的副檔名為 .zip 或 .jar,則合併檔案中的項目將會合併至 outfile 中。副檔名為其他任何副檔名的檔案都將會新增至輸出檔案中,即使它是在 mergefiles
元素中指定的。在 mergefiles
或 addfiles
元素中指定的目錄會如您所預期般新增至輸出檔案中:子目錄中的所有檔案都會遞迴地新增至輸出檔案中,並在輸出檔案中加上適當的前置詞(不合併)。
如果在要合併或新增的檔案中發現重複的項目和/或檔案,jlink
會合併或新增第一個項目,並略過所有後續的項目。
jlink
會略過 mergefiles 中的 META-INF 目錄。使用者應提供自己的輸出檔案明細資訊。
可以精簡要 jlink 的檔案組。這可以使用 addfiles
和 mergefiles
巢狀元素上的 includes、includesfile、excludes、excludesfile 和 defaultexcludes 屬性來完成。使用 includes 或 includesfile 屬性,您可以使用樣式來指定要包含的檔案。exclude 或 excludesfile 屬性用於指定要排除的檔案。這也是使用樣式來完成的。最後,您可以使用 defaultexcludes 屬性來指定是否要使用預設排除。請參閱 目錄基礎任務 部分,了解檔案的包含/排除運作方式,以及如何撰寫樣式。樣式相對於基礎目錄。
屬性 | 說明 | 必要 |
---|---|---|
outfile | 輸出檔案路徑。 | 是 |
compress | 是否壓縮輸出。 true、 yes或 on會產生壓縮輸出。 |
否;預設為未壓縮(膨脹)輸出 |
mergefiles | 如果可能,要合併到輸出的檔案。 | 兩個中只有一個 |
addfiles | 要新增到輸出的檔案。 |
以下會將 mergefoo.jar 和 mergebar.jar 中的項目合併到 out.jar 中。 mac.jar 和 pc.jar 會以單一項目新增到 out.jar 中。
<jlink compress="false" outfile="out.jar"> <mergefiles> <pathelement path="${build.dir}/mergefoo.jar"/> <pathelement path="${build.dir}/mergebar.jar"/> </mergefiles> <addfiles> <pathelement path="${build.dir}/mac.jar"/> <pathelement path="${build.dir}/pc.zip"/> </addfiles> </jlink>
上述的非過時替代方案
<jar compress="false" destfile="out.jar"> <zipgroupfileset dir="${build.dir}"> <include name="mergefoo.jar"/> <include name="mergebar.jar"/> </zipgroupfileset> <fileset dir="${build.dir}"> <include name="mac.jar"/> <include name="pc.jar"/> </fileset> </jar>
假設檔案 foo.jar 包含兩個項目:bar.class 和 barnone/myClass.zip。假設檔案 foo.jar 的路徑為 build/tempbuild/foo.jar。以下範例會在 out.jar 中提供項目 tempbuild/foo.jar。
<jlink compress="false" outfile="out.jar"> <mergefiles> <pathelement path="build/tempbuild"/> </mergefiles> </jlink>
然而,下一個範例會在 out.jar 中產生兩個頂層項目,即 bar.class 和 barnone/myClass.zip
<jlink compress="false" outfile="out.jar"> <mergefiles> <pathelement path="build/tempbuild/foo.jar"/> </mergefiles> </jlink>