Ant Jetty plugin

There 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.
It's purpose is to provide almost the same functionality as Jetty plugin for Maven, e.g. dynamic application reloading, working directly on web application sources, tight integration with build system, etc.

For the impatient ones, there is already a demo provided in jetty-contrib repository for the Ant Jetty plugin.
It's good to have jetty compiled before running these tests, because the demo depends on Jetty JARs from the Maven repository. Alternatively, you can download these JARs manually from one of the Maven repositories. Please take a look at build.xml file in jetty-ant-demo folder for a list of needed JARs.

Modifying build.xml from jetty-ant-demo is also the easiest way to start playing with this plugin.

How to start?

(Obviously) Ant plugin depends on Jetty JARs, and so far it's necessary to build Jetty and then Ant plugin directly from sources. Here's how it goes:

  1. Get the latest jetty sources from http://dist.codehaus.org/jetty/
  2. Unpack jetty and build it with 'mvn install' (If you don't have Maven yet, grab it from http://maven.apache.org/)
  3. Go to the extras/ant/ folder and build ant plugin with 'mvn install'
  4. Go to <your M2 repo root>/repository/org/mortbay/jetty/jetty-ant and grab the jetty-ant plugin JAR.
  5. Get these files to run Jetty with JSP/Servlets support (find these in <your M2 repo root>/repository/org/mortbay/jetty):
  6. Put all the JARs inside one lib directory (let's say jetty-lib).

How to prepare build.xml file?

Let's start with an empty build.xml [file:
]

<project name="Jetty-Ant integration test" basedir=".">
</project>








Then, a jetty task must be defined:

<project name="Jetty-Ant integration test" basedir=".">
  <path id="jetty.plugin.classpath">
    <fileset dir="jetty-lib" includes="*.jar"/>
  </path>
  <taskdef classpathref="jetty.plugin.classpath" resource="tasks.properties" loaderref="jetty.loader" />
</project>





Now, we are ready to add a new target with Jetty container declaration:

<project name="Jetty-Ant integration test" basedir=".">
  <path id="jetty.plugin.classpath">
    <fileset dir="jetty-lib" includes="*.jar"/>
  </path>
  <taskdef classpathref="jetty.plugin.classpath" resource="tasks.properties" loaderref="jetty.loader" />

  <target name="jetty.run">
    <jetty />
  </target>
</project>








Starting jetty on port 8080 is then a simple matter of executing ant jetty.run from the command line.

How to deploy web applications?

Adding web applications to the Jetty web server is now a simple matter of putting extra webapp tags inside jetty tag.
Notice, that a tempDirectory attribute has been added to the jetty task to specify where temporary files are stored.

<project name="Jetty-Ant integration test" basedir=".">
  <path id="jetty.plugin.classpath">
    <fileset dir="jetty-lib" includes="*.jar"/>
  </path>
  <taskdef classpathref="jetty.plugin.classpath" resource="tasks.properties" loaderref="jetty.loader" />

  <target name="jetty.run">
    <jetty tempDirectory="jetty-temp">
      <webApp name="webapp1" warfile="webapp1.war" contextpath="/webapp1" />
    </jetty>
  </target>
</project>








It's possible to put many webapp tags inside jetty tag, thus to deploy many web applications simultaneously.

Plugin syntax

There are many ways to configure jetty task:

There are also many ways to configure web applications with webapp tag: