使用 Ant 1.6.2 版或更新版本,Catalina 任務(wù)提供選項(xiàng),利用屬性或外部文件捕獲輸出。它們直接支持 類型屬性的子集:
|
屬性 |
屬性說明 |
是否必需 |
|
output |
輸出文件名。如果錯(cuò)誤流沒有重定向到一個(gè)文件或?qū)傩陨希鼘⒊霈F(xiàn)在輸出中。 |
否 |
|
error |
命令的標(biāo)準(zhǔn)錯(cuò)誤應(yīng)該被重定向到的文件。 |
否 |
|
logError |
用于在 Ant 日志中顯示錯(cuò)誤輸出,將輸出重定向至某個(gè)文件或?qū)傩浴ee(cuò)誤輸出不會(huì)包含在輸出文件或?qū)傩灾?。如果利?nbsp;error 或 errorProperty 屬性重定向錯(cuò)誤,則沒有任何效果。 |
否 |
|
append |
輸出和錯(cuò)誤文件是否應(yīng)該附加或覆蓋。默認(rèn)為 false。 |
否 |
|
createemptyfiles |
是否應(yīng)該創(chuàng)建輸出和錯(cuò)誤文件,哪怕是空的文件。默認(rèn)為 true。 |
否 |
|
outputproperty |
用于保存命令輸出的屬性名。除非錯(cuò)誤流被重定向至單獨(dú)的文件或流,否則這一屬性將包含錯(cuò)誤輸出。 |
否 |
|
errorproperty |
用于保存命令標(biāo)準(zhǔn)錯(cuò)誤的屬性名。 |
否 |
還可以指定其他一些額外屬性:
|
屬性 |
屬性說明 |
是否必需 |
|
alwaysLog |
該屬性用于查看捕獲的輸出,這個(gè)輸出也出現(xiàn)在 Ant 日志中。除非捕獲任務(wù)輸出,否則千萬不要使用它。默認(rèn)為 false。Ant 1.6.3 通過 直接支持該屬性。 |
否 |
|
failonerror |
用于避免因?yàn)?manager 命令處理中錯(cuò)誤而導(dǎo)致 Ant 執(zhí)行終止情況的發(fā)生。默認(rèn)為 true。如果希望捕獲錯(cuò)誤輸出,則必須設(shè)為false,否則 Ant 執(zhí)行將有可能在未捕獲任何輸出前就被終止。該屬性只用于 manager 命令的執(zhí)行上,任何錯(cuò)誤的或丟失的命令屬性仍然會(huì)導(dǎo)致 Ant 執(zhí)行終止。 |
否 |
它們還支持內(nèi)嵌的 元素,你可以在這些元素中指定全套的屬性。但對于input、inputstring、inputencoding,即使接收,也無法使用,因?yàn)樵谶@種上下文中它們沒有任何意義。詳情可參考 Ant 手冊以了解 元素的各個(gè)屬性。
下面這個(gè)范例摘錄了一段構(gòu)建文件,展示了這種對輸出重定向的支持是如何運(yùn)作的。
<target name="manager.deploy"
depends="context.status"
if="context.notInstalled">
<deploy url="${mgr.url}"
username="${mgr.username}"
password="${mgr.password}"
path="${mgr.context.path}"
config="${mgr.context.descriptor}"/>
</target>
<target name="manager.deploy.war"
depends="context.status"
if="context.deployable">
<deploy url="${mgr.url}"
username="${mgr.username}"
password="${mgr.password}"
update="${mgr.update}"
path="${mgr.context.path}"
war="${mgr.war.file}"/>
</target>
<target name="context.status">
<property name="running" value="${mgr.context.path}:running"/>
<property name="stopped" value="${mgr.context.path}:stopped"/>
<list url="${mgr.url}"
outputproperty="ctx.status"
username="${mgr.username}"
password="${mgr.password}">
</list>
<condition property="context.running">
<contains string="${ctx.status}" substring="${running}"/>
</condition>
<condition property="context.stopped">
<contains string="${ctx.status}" substring="${stopped}"/>
</condition>
<condition property="context.notInstalled">
<and>
<isfalse value="${context.running}"/>
<isfalse value="${context.stopped}"/>
</and>
</condition>
<condition property="context.deployable">
<or>
<istrue value="${context.notInstalled}"/>
<and>
<istrue value="${context.running}"/>
<istrue value="${mgr.update}"/>
</and>
<and>
<istrue value="${context.stopped}"/>
<istrue value="${mgr.update}"/>
</and>
</or>
</condition>
<condition property="context.undeployable">
<or>
<istrue value="${context.running}"/>
<istrue value="${context.stopped}"/>
</or>
</condition>
</target>
警告:多次調(diào)用 Catalina 任務(wù)往往并不是一個(gè)好主意,退一步說這樣做的意義也不是很大。如果 Ant 任務(wù)依賴鏈設(shè)定糟糕的話,即使本意并非如此,也會(huì)導(dǎo)致在一次 Ant 運(yùn)行中多次運(yùn)行任務(wù)。必須提前對你稍加警告,因?yàn)橛锌赡墚?dāng)你從任務(wù)中捕獲輸出時(shí),會(huì)出現(xiàn)一些意想不到的情況: