Robo Home | Ant | Changes | Preferences | AllPages

Hexkids sample Ant build.xml:
<?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}"/>

        <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=""/>


	<!-- 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"/>
	<!-- PREPARE: Create directories for generated files -->
	<target name="prepare" depends="init" description="Create the generated directories">
		<mkdir dir="jars"/>
		<mkdir dir="classes"/>
	<!-- 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"/>
	<!-- 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"/>
	<!-- 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 name="javadoc" depends="compile" description="Generate the JavaDoc Documentation">
        <delete dir="javadoc"/>
        <mkdir dir="javadoc"/>
        <javadoc sourcepath="src" destdir="javadoc" packagenames="*" classpath="{CLASSPATH}"/>
	<!-- FULL: Default target which rebuilds and redeploys the whole application & generates the JavaDoc-->
	<target name="full" depends="cleanlocal,deployjar,javadoc"/>

How I Use Ant

First of all make sure that you have Apache Ant installed. It can be downloaded from [Ant Home Page]. Probably easiest to add the Ant/bin directory to your PATH environment variable.

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:


  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 NameDescription
cleanlocalDelete the automatically generated directories i.e. classes & jar.
prepareCreate the classes & jar directories.
compileCompile all of the Java classes in the project that need compilation.
buildjarCreate the JAR file that contains the classes & the properties of the Robot
deployjarCopy the JAR file to the robocode/robots directory
javadocGenerate documentation on my robot. This documentation is the standard JavaDoc? for the all of the classes defined in my Robot
fullDo 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.

To Do

Trying to create the following Ant tasks:

Robo Home | Ant | Changes | Preferences | AllPages
Edit text of this page | View other revisions
Last edited March 15, 2003 23:42 EST by Hexkid (diff)