To start and stop Jetty from Ant command line, we can use the Ant Jetty plugin jetty-ant in the codehouse trunk, it is a new plugin available in the /extras/ant location, which makes it possible to start Jetty web server directly from the Ant build script, and, actually, to embed the Jetty web server inside your build process.

1. Please download and install Jetty and its extras, if jetty-ant jar does not exist get it jetty-ant jar, copy it to either project or ant lib folder.

2. Create a Ant build XML, define a task jetty, taskdef exports jetty task available from the loading classes(it is not a standard task).

<project name="Start jetty from ant" basedir=".">
   <path id="jetty.cp">
      <fileset dir="jetty-lib" includes="*.jar"/>
   <taskdef classpathref="jetty.cp" resource="" loaderref="jetty.loader" />

3. Add a new target ‘jetty’, create a folder ${jetty.temp} which specify where temporary files are stored, then and extra tags webapp and connectors inside jetty tag.

connectors – defines Jetty connectors (what’s channel connector).

webapp – a particular web application will be deployed to.

<target name="jetty" depends="init">
   <mkdir dir="logs"/><!-- this must be in the working directory and must exist -->
   <typedef name="selectchannelconnector" classname="org.mortbay.jetty.nio.SelectChannelConnector"
classpathref="jetty.cp" loaderref="jetty.loader"/>
   <mkdir dir="${jetty.temp}"/>
   <jetty tempDirectory="${jetty.temp}">
         <selectchannelconnector port="80" />
      <webapp name="Web Application" warfile="${dist.dir}/${}" contextpath="/">
         <classes dir="./src/resources" includes="logback-test.xml">

4. Run ant target jetty to start web app.