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