<?xml version="1.0"?> <project name="Robocode" default="deployjar" basedir="."> <!-- INIT: Set constants for project --> <target name="init"> <property name="ROBOTNAME" value="MyRobot"/> <property name="package" value="MyPackage"/> <!-- Create the property file that describes this robot --> <propertyfile file="${ROBOTNAME}.properties"> <entry key="robot.description" value=""/> <entry key="robot.java.source.included" value="true"/> <entry key="robocode.version" value="1.0.6"/> <entry key="robot.version" value="0.1"/> <entry key="robot.author.name" value=""/> <entry key="robot.classname" value="${package}.${ROBOTNAME}"/> </propertyfile> <property file="${ROBOTNAME}.properties" description="Use the entries from the properties file within this script."/> <property name="ROBOCODE_HOME" value="c:\robocode"/> <property name="JAR_NAME" value="${robot.classname}_${robot.version}.jar"/> <property name="COMPILE_WITH_DEBUG" value="off"/> <property name="VERBOSE_LEVEL" value="1"/> <property name="CLASSPATH" value="./classes;${ROBOCODE_HOME}/robocode.jar"/> <property name="COMPILECLASSNAME" value=""/> </target> <!-- CLEANLOCAL: Delete the local filesystem directories which contain generated files --> <target name="cleanlocal" depends="init" description="Remove the directories containing the classes and the jar file"> <delete dir="jars"/> <delete dir="classes"/> </target> <!-- PREPARE: Create directories for generated files --> <target name="prepare" depends="init" description="Create the generated directories"> <mkdir dir="jars"/> <mkdir dir="classes"/> </target> <!-- COMPILE: Compile all java files in the project This task will compile all classes that have been modified since the previous compilation. --> <target name="compile" depends="prepare" description="Compile the Java classes"> <javac srcdir="src" destdir="classes" classpath="${CLASSPATH}" debug="${COMPILE_WITH_DEBUG}" includes="**/*.java"/> </target> <!-- BUILDCOMPONENTJAR: Build the war jar file containing classes, jars, jsps, images, html files, and deployment descriptor --> <target name="buildjar" depends="compile" description="Construct the Jar file containing the robot"> <!-- Build the JAR containing all of the classes --> <jar jarfile="jars/${JAR_NAME}" filesonly="true"> <fileset dir="classes" includes="**\*.class"/> <fileset dir="src" includes="**\*.java"/> <fileset dir="." includes="${ROBOTNAME}.properties"/> </jar> </target> <!-- DEPLOYJAR: Deploy the jar to the robocode/robots directory --> <target name="deployjar" depends="buildjar" description="Copy the Robot Jar file to Robocode/robots directory"> <copy file="jars/${JAR_NAME}" overwrite="true" todir="${ROBOCODE_HOME}/robots"/> </target> <target name="javadoc" depends="compile" description="Generate the JavaDoc Documentation"> <delete dir="javadoc"/> <mkdir dir="javadoc"/> <javadoc sourcepath="src" destdir="javadoc" packagenames="*" classpath="{CLASSPATH}"/> </target> <!-- FULL: Default target which rebuilds and redeploys the whole application & generates the JavaDoc--> <target name="full" depends="cleanlocal,deployjar,javadoc"/> </project>
I tend to create a new directory for each Robot that I work on & treat each Robot as a separate project.
This directory has the following format:
RobotNameDir?
src - The source code for the Robot. This is the parent directory of my Java package structure. classes - Where the Java classes are created by the compiler. This directory will be automatically created by the Ant script. javadoc - The automatically generated documentation for my Robot's classes. jars - The directory that holds the JAR file for the robot after it has been packaged.
The Sample Ant Build file contains the following targets:
Target Name | Description |
cleanlocal | Delete the automatically generated directories i.e. classes & jar. |
prepare | Create the classes & jar directories. |
compile | Compile all of the Java classes in the project that need compilation. |
buildjar | Create the JAR file that contains the classes & the properties of the Robot |
deployjar | Copy the JAR file to the robocode/robots directory |
javadoc | Generate documentation on my robot. This documentation is the standard JavaDoc? for the all of the classes defined in my Robot |
full | Do everything |
The build file also includes the inter-dependancies between the tasks. For example, if you specify the 'deployjar' target Ant will compile any classes that need compiling & then build the jar before it is deployed.