apache > cocoon

- Home

# Offline Page Generation with Apache Ant

## Overview

Apache Ant can be used to start Cocoon in its Offline mode. A specific Ant task is available, allowing the user to embed the Cocoon configuration information into Ant's build script.

## Configuring the Ant task

The main configuration for the task is to specify a `cocoon.context` property which points to the Cocoon webapp from which the pages or site are to be generated.

From this property, a classpath can be created. By default, this should point to `WEB-INF/classes` and all jar files in `WEB-INF/lib`. Futher classpaths can be added if they are needed.

The taskdef requires this classpath in order to invoke the Ant task, and the task itself needs the classpath in order to invoke Cocoon.

Beyond these configurations, the rest are the same as is used by the Command Line interface, and is detailed on the configuration page.

## Sample Ant Task

A sample ant build file is shown below. This sample shows only that which is required to configure the Ant task. For further details of configuring Cocoon, see the configuration page.

    <?xml version="1.0"?>
    <project default="cocoon" basedir=".">

        <property name="cocoon.context" value="../cocoon/build/webapp"/>
        <path id="cocoon.classpath">
          <dirset dir="${cocoon.context}/WEB-INF/classes"/>
          <fileset dir="${cocoon.context}/WEB-INF/lib" includes="*.jar"/>
        </path>

        <taskdef name="cocoon" classname="org.apache.cocoon.CocoonTask" classpathref="cocoon.classpath"/>

        <target name="cocoon">

            <cocoon verbose="true"
                    classpathref="cocoon.classpath"
                    follow-links="true"
                    precompile-only="false"
                    confirm-extensions="false"
                    context-dir="${cocoon.context}"
                    config-file="WEB-INF/cocoon.xconf"
                    work-dir="build/work"
                    dest-dir="build/dest"
                    default-filename="index.html"
                    accept="*/*">

               <broken-links type="xml"
                             file="brokenlinks.xml"
                             generate="false"
                             extension=".error"/>

               <logging log-kit="${cocoon.context}/WEB-INF/logkit.xconf" logger="cli" level="DEBUG" />

               <uris name="site" follow-links="true">
                   <uri type="append"
                        src-prefix=""
                        src="index.html"
                        dest="${cocoon.context}/build/dest/"/>
               </uris>
            </cocoon>
        </target>
    </project>

Errors and Improvements? If you see any errors or potential improvements in this document please help us: View, Edit or comment on the latest development version (registration required).