事情是這樣的 html
我要用Ant發送郵件,可是郵件內容是會動態變化的,每次可能不同,這樣子,我須要用過一個腳本動態生成郵件內容文件,有兩個問題要解決: java
1. 如何生成文件? apache
2.若是將生成的文件加載到Ant裏面? 測試
首先我找到了解決第二個問題的方法,就是使用Ant的LoadFile task,實現以下: ui
郵件內容放在 content.template裏面 spa
GENERAL INFO BUILD Build URL: Project: Date of build: Build duration:
在Ant里加上以下代碼: code
<loadfile property="email_content" srcFile="./content.template"/>
而後再發送郵件 orm
<mail mailhost="${mail_server}" subject="${mail_subject}" cclist="${mail_distribution}" ignoreInvalidRecipients="true" messagemimetype="text/html"> <from address="${mail_fromaddress}" /> <replyto address="${mail_replyto}" /> <message>${email_content}</message> <attachments> <fileset dir="${doc_dir_release}"> <include name="${content_list_file_xml}" /> <include name="${content_list_file_html}" /> </fileset> </attachments> </mail>應就能夠了,不過尚未測試驗證。
另外Filterchain 能夠實現將目標文件中的動態參數以property替換(f the data contains data that represents Ant properties (of the form ${...}), that is substituted with the property's actual value.): server
如文件loadfile1.tmp 裏面內容爲All these moments will be lost in time, like tear drops in the ${weather} xml
Ant文件:
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <project name="test" default="test"> <target name="test"> <property name="weather" value="rain" /> <loadfile property="modifiedmessage" srcFile="./loadfile1.tmp"> <filterchain> <expandproperties /> </filterchain> </loadfile> <echo message="---+${modifiedmessage}" /> </target> </project>輸出爲: [echo] ---+All these moments will be lost in time, like tear drops in the rain
而將${weather}替換爲rain,則就是expandproperties的功勞了