jarlib-resolve

說明

嘗試找出一個 jar 來滿足延伸模組,並將 jar 的位置放入屬性中。此任務允許您新增許多解析器,這些解析器有能力為特定延伸模組找出一個程式庫。每個解析器都將按照指定的順序嘗試,直到找到程式庫或沒有任何解析器為止。如果沒有任何解析器,且 failOnError 為 true,則會擲回 BuildException

請注意,此任務使用「選用套件」規格中定義的延伸模組。如需有關選用套件的更多資訊,請參閱 Java Standard Edition 套件文件套件中檔案 guide/extensions/versioning.html 中的文件 選用套件版本控管,或參閱線上 延伸模組和延伸模組集文件 以取得更多詳細資料。

參數

屬性 說明 必要
property 要設定為程式庫位置的屬性名稱。
failOnError 如果找不到程式庫,true 會導致建置例外。 否;預設為 true
checkExtension 如果嵌套解析器傳回的程式庫應該檢查是否提供延伸模組,則為 true 否;預設為 true

指定為嵌套元素的參數

extension

Extension 要解析的延伸模組。必須存在

location

location 嵌套元素允許您在相對於專案目錄的位置尋找程式庫。

屬性 說明 必要
location 程式庫的路徑名稱。

url

url 解析器允許您從 URL 下載程式庫到本機檔案。

屬性 說明 必要
url 要下載的 URL。
destfile 要將 URL 下載到的檔案。 兩個中只有一個
destdir 要放置已下載檔案的目錄。

ant

ant 解析器允許您執行 Apache Ant 建置檔案來產生程式庫。

屬性 說明 必要
antfile 建置檔案。
destfile ant 建置建立的檔案。
target 要在建置檔案中執行的目標。

範例

將延伸模組解析到檔案。如果檔案不存在或檔案未實作延伸模組,則擲回例外。

<extension id="dve.ext"
           extensionName="org.realityforge.dve"
           specificationVersion="1.2"
           specificationVendor="Peter Donald"/>

<jarlib-resolve property="dve.library">
  <extension refid="dve.ext"/>
  <location location="/opt/jars/dve.jar"/>
</jarlib-resolve>

將延伸模組解析到 URL。如果 URL 不存在或無法寫入 destfile,或檔案未實作延伸模組,則擲回例外。

<extension id="dve.ext"
           extensionName="org.realityforge.dve"
           specificationVersion="1.2"
           specificationVendor="Peter Donald"/>

<jarlib-resolve property="dve.library">
  <extension refid="dve.ext"/>
  <url url="https://www.example.com/jars/dve.jar" destfile="lib/dve.jar"/>
</jarlib-resolve>

將延伸模組解析到 Ant 建置產生的檔案。如果檔案未產生,或 Ant 檔案遺失,或建置失敗,則擲回例外。(注意:不會檢查程式庫是否實作延伸模組。)

<extension id="dve.ext"
           extensionName="org.realityforge.dve"
           specificationVersion="1.2"
           specificationVendor="Peter Donald"/>

<jarlib-resolve property="dve.library" checkExtension="false">
  <extension refid="dve.ext"/>
  <ant antfile="../dve/build.xml" target="main" destfile="lib/dve.jar"/>
</jarlib-resolve>

透過多種方法解析擴充功能。首先檢查本機檔案,看看它是否實作擴充功能。如果沒有,則嘗試從平行目錄中的來源建立它。如果失敗,最後嘗試從網站下載它。如果所有步驟都失敗,則擲回建置例外狀況。

<extension id="dve.ext"
           extensionName="org.realityforge.dve"
           specificationVersion="1.2"
           specificationVendor="Peter Donald"/>

<jarlib-resolve property="dve.library">
  <extension refid="dve.ext"/>
  <location location="/opt/jars/dve.jar"/>
  <ant antfile="../dve/build.xml" target="main" destfile="lib/dve.jar"/>
  <url url="https://example.com/jars/dve.jar" destfile="lib/dve.jar"/>
</jarlib-resolve>