27 Feb 2012 [ 185 week8 hw ]

Large software projects can require a very complex process to compile the code and package the resulting executable to be distributed. This process can involve many steps, such as testing and packaging resources and configuration files. For this reason, it's useful to automate as much of the process as possible, even for small projects.

You might have been using an IDE like NetBeans or Eclipse to provide some of this functionality: those IDEs will automatically compile your project, and possible perform other tasks such as testing or generating documentation. We're going to use Apache Ant to illustrate how to generalize this process.


Ant uses XML format for its configuration file. XML is a markup language that can be used to model hierarchical data. There are tons of tools available for parsing, transforming, and displaying data described using XML.


To install (on Windows; other operating systems are easier), download Ant unzip it to any desired location, and set the following environment variables:

The course materials contain a very simple example that we'll build on in class (see the examples/ant-example directory). Here's the Ant setup file, that we'll improve and add to:

  <property name="build.dir" location="build" />
  <property name="src.dir" location="src" />

  <target name="hello" description="Print a greeting">
    <echo message="Hello!" />

  <target name="init">
    <mkdir dir="${build.dir}" />
  <target name="compile" depends="init">
    <javac srcdir="${src.dir}" destdir="${build.dir}" />
  <target name="dist" depends="compile">
    <jar destfile="Hello.jar" basedir="${build.dir}">
        <!-- This is XML comment syntax -->
        <!-- Switched to graphical main class to work 
             on default Windows setup -->
        <attribute name="Main-Class" value="HelloGUI" />

The dist target will package the program and allow it to run like a normal executable (on Windows at least). However, the default Windows setup is to run it expecting a graphical interface. You can see the setup by typing ftype jarfile. I edited the project so that it now uses a graphical program as the default main class in the jar file.


For XML information, check out this XML tutorial. For tons more detail, check out the introductory chapters of Beginning XML.

For Ant, start with this Ant tutorial, which is part of the extensive Ant manual. See the intro chapters in Ant in Action for lots more information.


  1. Write a description of your favorite recipe using XML. To do this, decide what tags to use to describe things like ingredients, measurements, and step descriptions.

  2. Find examples of 2 other file formats that are based on XML, and describe what they're for. Show a small example, if possible. For example, SVG is a format for vector graphics, and a simple example looks like:

    <svg xmlns="http://www.w3.org/2000/svg" version="1.1">
      <circle cx="100" cy="50" r="50" fill="black" />
      <circle cx="100" cy="50" r="40" fill="orange" />
      <circle cx="100" cy="50" r="30" fill="black" />
      <circle cx="100" cy="50" r="20" fill="orange" />
      <circle cx="100" cy="50" r="10" fill="black" />

    And the processed file looks like:

  3. Find a previous homework assignment in which you used Java, and create an Ant build setup for it. Include a target that will run one of the programs in your assignment (see the java task type).

To submit, either do your work in your 185-hw repository in a folder called hw7 (and post to your BitBucket account when you're done), or email your answers in a zip file to jal2016@email.vccs.edu with subject CSC 185 HW7.

Due Tuesday, Mar 20.