Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
an example of a simple ant/ivy templates w/sitebricks and jetty i like to start with
<?xml version="1.0" encoding="UTF-8"?>
<project name="AntTmplt" xmlns:ivy="antlib:org.apache.ivy.ant" default="run" basedir=".">
<target name="all" depends="setup,resolve" description="Build, compile, and package the entire application">
<!-- Now we compile and package our project. -->
<antcall target="compile"/>
<antcall target="package" />
<target name="clearcache" description="Clear the Apache Ivy cache" depends="setup,ivySettings">
<ivy:cleancache />
<target name="ivySettings">
<ivy:settings file="ivysettings.xml" />
<target name="resolve" description="Retrieve dependencies with Apache Ivy" depends="ivySettings">
<ivy:retrieve />
<property name="ivy.install.version" value="2.1.0-rc2" />
<condition property="ivy.home" value="${env.IVY_HOME}">
<isset property="env.IVY_HOME" />
<property name="ivy.home" value="${user.home}/.ant" />
<property name="ivy.jar.dir" value="${ivy.home}/lib" />
<property name="ivy.jar.file" value="${ivy.jar.dir}/ivy.jar" />
<target name="download-ivy" unless="hasDownloadedIvy">
<property name="hasDownloadedIvy" value="true" />
<mkdir dir="${ivy.jar.dir}"/>
<!-- download Ivy from web site so that it can be used even without any special installation -->
<get src="${ivy.install.version}/ivy-${ivy.install.version}.jar"
dest="${ivy.jar.file}" usetimestamp="true"/>
<target name="init-ivy" depends="download-ivy">
<!-- try to load ivy here from ivy home, in case the user has not already dropped
it into ant's lib dir (note that the latter copy will always take precedence).
We will not fail as long as local lib dir exists (it may be empty) and
ivy is in at least one of ant's lib dir or the local lib dir. -->
<path id="ivy.lib.path">
<fileset dir="${ivy.jar.dir}" includes="*.jar"/>
<taskdef resource="org/apache/ivy/ant/antlib.xml"
uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/>
<target name="setup" description="Setup build dependencies and properties" depends="init-ivy">
<property environment="env"/>
<property name="root" location="${basedir}"/>
<property name="build" location="${basedir}/build"/>
<property name="ivy.lib.dir" value="${build}/lib"/>
<property name="src" location="${root}/src/main/java"/>
<property name="target" location="${root}/target"/>
<property name="target.www" location="${target}/www"/>
<property name="target.classes" location="${target}/classes"/>
<mkdir dir="${target}"/>
<mkdir dir="${target.classes}"/>
<mkdir dir="${target.www}"/>
<target name="compile" description="Call the Java compiler for this project">
<!-- Compile all the Java -->
<javac srcdir="${src}/com/example/server" destdir="${target.classes}"
target="1.5" source="1.5" debug="true" deprecation="yes"
<compilerarg value="-Xlint" />
<fileset dir="${root}/build/lib">
<include name="**/*.jar"/>
<pathelement path="${java.class.path}"/>
<target name="package" description="Package the contents of this project into AntTmplt.war">
<!-- Create the distribution directory -->
<delete file="${target}/AntTmplt.war" />
<war destfile="${target}/AntTmplt.war" webxml="web.xml">
<fileset dir="${target.www}"/>
<zipfileset dir="${target.classes}" prefix="WEB-INF/classes" >
<include name="**/*"/>
<target name="run" depends="setup,resolve,all,jetty.setup"
description="Run this Web Project with an embedded Jetty server">
Setup for Jetty
<path id="jetty.plugin.classpath">
<fileset dir="${build}/lib" includes="*.jar"/>
<taskdef classpathref="jetty.plugin.classpath" resource="" loaderref="jetty.loader" />
Running this Web Application with an embedded
Jetty server. Press Ctrl+C to stop the server.
Access AntTmplt at: http://localhost:8080
<jetty tempDirectory="${root}/jetty-temp">
<webApp name="AntTmplt" warfile="${target}/AntTmplt.war" contextpath="/" />
<target name="jetty.setup">
<fail message="The AntTmplt.war file is missing. You must build the WAR with the all target before you can run.">
<available file="${target}/AntTmplt.war"/>
<target name="clean" depends="setup" description="Remove the artifacts generated by this build">
<delete dir="${target}"/>
<delete dir="${build}/lib"/>
<delete dir="${root}/jetty-temp"/>
<ivy-module version="2.0"
<info organisation="com.example" module="AntTmplt-ivy" />
<!-- client deoendencies -->
<!-- none -->
<!-- server dependencies -->
<dependency org="" name="sitebricks"
rev="0.8.5" />
<dependency org="" name="guice" rev="3.0" />
<!-- We don't really need Jetty to build, but we use it to run the Jetty
server in process. -->
<dependency org="jetty" name="org.mortbay.jetty" rev="5.1.12" />
<dependency org="org.mortbay.jetty" name="jetty-ant" rev="6.1.25" />
<?xml version="1.0" encoding="UTF-8"?>
<settings defaultResolver="mainchain" />
<chain name="mainchain">
<ibiblio name="main" m2compatible="true" />
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="AntTmplt" version="2.5" xmlns=""
<!-- Servlets -->
<!-- none -->
<!-- Filters -->
<!-- Default page to serve -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment