近期在學習使用struts,使用過程中會涉及到struts資源的文件的使用,這個資源文件又必須通過jdk的命令 native2ascii 轉換字符編碼。想起來我經常修改資源文件,然后每次修改都要打開控制臺,cd 到資源文件目錄,然后在執行 命令native2ascii -encoding gb2312 ??,真是好痛苦的經歷啊。
所以我決定使用ant解決這個難題。讓ant自動為我服務,呵呵。好懶的我啊!
打開 ant的文檔,找到了task exec,是執行系統命令,其中的dir 參數為執行的目錄,executable是執行的命令,還有一個參數為 執行命令的參數,請參考以下例子:
<target name="make resource">
<!— 刪除舊的資源文件,因為native2ascii不會自動刪除,會出現異常-->
<delete
file="${resource}/ApplicationResources_zh_CN.properties">
</delete>
<!— 執行命令進行資源文件轉換 -->
<exec dir="${resource}" executable="native2ascii" >
<arg line="-encoding gb2312
ApplicationResources_zh_CN.properties.txt
ApplicationResources_zh_CN.properties"/>
</exec>
</target>
測試一下吧,是不是看到了結果:
make resource:
[delete] Deleting: E:\My Webs\jspMyAdmin\src\com\guipei\struts\ApplicationResources_zh_CN.properties
BUILD SUCCESSFUL
Total time: 1 second