Ant Task Examples - 2016-06-02
Here is a basic example of Apache Ant task.
Define properties, using this value ${property} like valuables
<property name="tomcat.host" value="192.168.1.250" /> <property name="tomcat.port" value="8080" /> <property name="username" value="tomcat" /> <property name="password" value="password" />
Java Task
<target name="run"> <java classname="Main"> <classpath> <pathelement location="classes"/> <pathelement path="${java.class.path}"/> </classpath> </java> </target>
Javac Task
<target name="compile"> <javac srcdir="src" destdir="classes" executable="${compiler}" includeantruntime="false"></javac> </target>
Execute other commands
<target name="run-jsp"> <exec executable="curl"> <arg line="http://${tomcat.host}:${tomcat.port}/${appName}/test.jsp" /> </exec> </target>
Remove/Create directories
<target name="cleanup"> <delete dir="${classes}" /> <mkdir dir="${classes}" /> </target>
Copy files
<target name="copy"> <copy file="web.xml" todir="WEB-INF/" /> <copy file="test.jsp" todir="jsp/" /> <copy todir="WEB-INF/jsp/"> <fileset dir="."> <include name="*.jsp"></include> <exclude name="test.jsp"></exclude> </fileset> </copy> </target>
ZIP
<target name="zip"> <zip basedir="${builddir}" destfile="${appName}.war" /> </target>