Jetty has moved!
Jetty is a project at the Eclipse Foundation.
Homepage:http://www.eclipse.org/jetty
Downloads: http://download.eclipse.org/jetty/
Documentation:http://www.eclipse.org/jetty/documentation/current/
About:http://www.eclipse.org/jetty/about.php
Jetty Powered:http://www.eclipse.org/jetty/powered/
Contact the core Jetty developers at www.webtide.com
private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services from 1 day to full product delivery
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

Jetty Ant 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, so it is necessary to get some files (semi) manually.
You can find them in one of the M2 repositories

  1. Get jetty sources from the SVN repository (TODO: are jetty-contrib builds included in the Jetty CI builds?).
  2. Build them with 'mvn install'
  3. Go to <your M2 repo root>/repository/org/mortbay/jetty/jetty-ant and grab the jetty-ant plugin JAR.
  4. Get these files to run Jetty with JSP/Servlets support.
    • jetty.jar
    • jetty-util.jar
    • jetty-plus.jar
    • jetty-naming.jar
    • servlet-api-2.5.jar
    • jsp-api-2.1.jar
    • jsp-2.1.jar
    • and core-3.1.1.jar from <M2 repository>/org/eclipse/jdt/core/3.1.1/
  5. 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:

Then, a jetty task must be defined:

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

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.

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:

  • tempDirectory - specifies the Jetty temporary web directory:
  • requestLog - defines a request logger:
  • jettyXml - applies additional configuration via a standard jetty.xml file:
  • systemProperties - adds system properties when starting Jetty:
  • connectors - defines Jetty connectors (a better way still needs to be developed):
  • userRealms - adds authentication via user "realms":

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

  • name - name of a web application, which is used by DefaultServlet to display application description
  • warfile - path to .war file or a directory with web application contents:
  • contextPath - a context path a particular web application will be deployed to, and thus where it will be accessible (http://localhost:8080/webapp in this case):
  • jettyEnvXml - path to jettyEnv.xml file with JNDI resource declarations
  • webXml - path to web.xml file. If not specified, the default (location-of-war-file/WEB-INF/web.xml) location is used:
  • scanTargets and scanIntervalSeconds - used to point to a special files/folders which need to be scanned and specify scanner interval in seconds respectively. If any of files changes the web application is being automatically reloaded. Scan interval and scanned files can be adjusted per web application.
  • lib - specifies which libraries needs to be included for a particular web application (treated as files inside WEB-INF/lib folder). Multiple lib tags are allowed.
  • classes - specifies which folder contains web application classes (treated as WEB-INF/classes folder). Multiple classes tags are allowed.
  • connectors - specifies additional web application connectors
  • No labels
Contact the core Jetty developers at www.webtide.com
private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services from 1 day to full product delivery