Skip to content

Instantly share code, notes, and snippets.

@danlangford
Created November 18, 2011 21:03
Show Gist options
  • Save danlangford/1377755 to your computer and use it in GitHub Desktop.
Save danlangford/1377755 to your computer and use it in GitHub Desktop.
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>
<target name="clearcache" description="Clear the Apache Ivy cache" depends="setup,ivySettings">
<ivy:cleancache />
</target>
<target name="ivySettings">
<ivy:settings file="ivysettings.xml" />
</target>
<target name="resolve" description="Retrieve dependencies with Apache Ivy" depends="ivySettings">
<ivy:retrieve />
</target>
<property name="ivy.install.version" value="2.1.0-rc2" />
<condition property="ivy.home" value="${env.IVY_HOME}">
<isset property="env.IVY_HOME" />
</condition>
<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="http://repo2.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar"
dest="${ivy.jar.file}" usetimestamp="true"/>
</target>
<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"/>
</path>
<taskdef resource="org/apache/ivy/ant/antlib.xml"
uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/>
</target>
<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>
<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"
includeantruntime="false">
<compilerarg value="-Xlint" />
<classpath>
<fileset dir="${root}/build/lib">
<include name="**/*.jar"/>
</fileset>
<pathelement path="${java.class.path}"/>
</classpath>
</javac>
</target>
<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="**/*"/>
</zipfileset>
</war>
</target>
<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"/>
</path>
<taskdef classpathref="jetty.plugin.classpath" resource="tasks.properties" loaderref="jetty.loader" />
<echo>
========================================================================
Running this Web Application with an embedded
Jetty server. Press Ctrl+C to stop the server.
Access AntTmplt at: http://localhost:8080
========================================================================
</echo>
<jetty tempDirectory="${root}/jetty-temp">
<webApp name="AntTmplt" warfile="${target}/AntTmplt.war" contextpath="/" />
</jetty>
</target>
<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.">
<condition>
<not>
<available file="${target}/AntTmplt.war"/>
</not>
</condition>
</fail>
</target>
<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"/>
</target>
</project>
<ivy-module version="2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd"
xmlns:m="http://ant.apache.org/ivy/maven">
<info organisation="com.example" module="AntTmplt-ivy" />
<dependencies>
<!-- client deoendencies -->
<!-- none -->
<!-- server dependencies -->
<dependency org="com.google.sitebricks" name="sitebricks"
rev="0.8.5" />
<dependency org="com.google.inject" 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" />
</dependencies>
</ivy-module>
<?xml version="1.0" encoding="UTF-8"?>
<ivysettings>
<settings defaultResolver="mainchain" />
<resolvers>
<chain name="mainchain">
<ibiblio name="main" m2compatible="true" />
</chain>
</resolvers>
</ivysettings>
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="AntTmplt" version="2.5" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd">
<display-name>AntTmplt</display-name>
<!-- Servlets -->
<!-- none -->
<!-- Filters -->
<filter>
<filter-name>guiceFilter</filter-name>
<filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>guiceFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>com.example.anttmplt.AppConfig</listener-class>
</listener>
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment