build.xml
<?xml version="1.0" encoding="UTF-8"?><project><property name="src.dir" location="src"></property><property name="build.dir" location="build"></property><property name="build.classes" location="${build.dir}/classes"></property><property name="build.war" location="${build.dir}/war"></property><property name="web.name" value="hello"></property><property name="web.root" value="WebContent"></property><property name="web.WEB-INF" location="${web.root}/WEB-INF"></property><property name="web.lib" location="${web.WEB-INF}/lib"></property><property environment="env"></property><path id="compile"><fileset dir="${web.lib}" includes="*.jar"></fileset><fileset dir="${env.CATALINA_HOME}/lib" includes="*.jar"></fileset></path><target name="init"><delete dir="${build.dir}"></delete><mkdir dir="${build.dir}"/><mkdir dir="${build.classes}"/><mkdir dir="${build.war}"/></target><target name="compile" depends="init"><javac destdir="${build.classes}" srcdir="${src.dir}" classpathref="compile"></javac></target><target name="war" depends="compile"><war destfile="${build.war}/${web.name}.war"><fileset dir="${web.root}" includes="**/*.*"></fileset><lib dir="${web.lib}"></lib><webinf dir="${web.WEB-INF}"></webinf><classes dir="${build.classes}"></classes></war></target><presetdef name="sql-admin"><sql userid="root" password="root" url="jdbc:mysql://localhost:3306/hibernate?useUnicode=true&characterEncoding=utf-8" driver="com.mysql.jdbc.Driver"><classpath refid="compile"></classpath></sql></presetdef><target name="init-mysql"><sql-admin><!-- 可以自訂sql檔案來執行<transaction src="sql.sql">--><transaction>drop database ant_test;create database ant_test;GRANT ALL ON ant_test.* TO "ant_test"@"localhost" IDENTIFIED BY '123'</transaction></sql-admin></target><target name="deploy" depends="war"><copy todir="${env.CATALINA_HOME}/webapps"><fileset dir="${build.war}" includes="${web.name}.war"></fileset></copy></target></project>