| <html><head> |
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |
| <title>Chapter 22. Using Ant with Jetty</title><link rel="stylesheet" type="text/css" href="css/docbook.css"><meta name="generator" content="DocBook XSL-NS Stylesheets V1.76.1"><meta name="keywords" content="jetty, servlet, servlet-api, cometd, http, websocket, eclipse, maven, java, server, software"><link rel="home" href="index.html" title="Jetty : The Definitive Reference"><link rel="up" href="development.html" title="Part IV. Jetty Development Guide"><link rel="prev" href="jetty-jspc-maven-plugin.html" title="Jetty Jspc Maven Plugin"><link rel="next" href="jetty-handlers.html" title="Chapter 23. Handlers"><link xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" rel="shortcut icon" href="images/favicon.ico"><script type="text/javascript" src="js/shCore.js"></script><script type="text/javascript" src="js/shBrushJava.js"></script><script type="text/javascript" src="js/shBrushXml.js"></script><script type="text/javascript" src="js/shBrushBash.js"></script><script type="text/javascript" src="js/shBrushJScript.js"></script><script type="text/javascript" src="js/shBrushSql.js"></script><script type="text/javascript" src="js/shBrushProperties.js"></script><script type="text/javascript" src="js/shBrushPlain.js"></script><link type="text/css" rel="stylesheet" href="css/shCore.css"><link type="text/css" rel="stylesheet" href="css/shThemeEclipse.css"><link type="text/css" rel="stylesheet" href="css/font-awesome.min.css"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><tr><td style="width: 25%"><a href="http://www.eclipse.org/jetty"><img src="images/jetty-header-logo.png" alt="Jetty Logo"></a><br><span style="font-size: small"> |
| Version: 9.3.0.v20150612</span></td><td style="width: 50%"><script type="text/javascript"> (function() { |
| var cx = '016459005284625897022:obd4lsai2ds'; |
| var gcse = document.createElement('script'); |
| gcse.type = 'text/javascript'; |
| gcse.async = true; |
| gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + |
| '//www.google.com/cse/cse.js?cx=' + cx; |
| var s = document.getElementsByTagName('script')[0]; |
| s.parentNode.insertBefore(gcse, s); |
| })(); |
| </script><gcse:search></gcse:search></td></tr></table><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 22. Using Ant with Jetty</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="jetty-jspc-maven-plugin.html"><i class="icon-chevron-left"></i> Previous</a> </td><th width="60%" align="center">Part IV. Jetty Development Guide<br><a accesskey="p" href="index.html"><i class="icon-home"></i> Home</a></th><td width="20%" align="right"> <a accesskey="n" href="jetty-handlers.html">Next <i class="icon-chevron-right"></i></a></td></tr></table><hr></div><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="jetty-callout"><h5 class="callout"><a href="http://www.webtide.com/">Contact the core Jetty developers at |
| <span class="website">www.webtide.com</span></a></h5><p> |
| 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 |
| </p></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a name="ant-and-jetty"></a>Chapter 22. Using Ant with Jetty</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="ant-and-jetty.html#jetty-ant">Using the Ant Jetty Plugin</a></span></dt></dl></div><p>This chapter explains how to use Jetty with Ant and the Jetty Ant |
| tasks.</p><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="jetty-ant"></a>Using the Ant Jetty Plugin</h2></div></div></div><div class="toc"><dl><dt><span class="section"><a href="ant-and-jetty.html#jetty-ant-preparation">Preparing Your Project</a></span></dt><dt><span class="section"><a href="ant-and-jetty.html#d0e17832">Preparing the <code class="filename">build.xml</code> file</a></span></dt><dt><span class="section"><a href="ant-and-jetty.html#d0e17861">Starting Jetty via Ant</a></span></dt><dt><span class="section"><a href="ant-and-jetty.html#d0e17868">Configuring the Jetty Container</a></span></dt><dt><span class="section"><a href="ant-and-jetty.html#d0e18061">Deploying a Web Application</a></span></dt></dl></div><p>The Ant Jetty plugin is a part of Jetty 9 under the <code class="code">jetty-ant</code> module. |
| This plugin makes it possible to start a Jetty web server directly from the |
| Ant build script, and to embed the Jetty web server inside your build |
| process. Its purpose is to provide almost the same functionality as the |
| Jetty plugin for Maven: dynamic application reloading, working directly on |
| web application sources, and tightly integrating with the build |
| system.</p><div class="informalexample"><script type="syntaxhighlighter" class="brush: xml;toolbar: false"> |
| <![CDATA[ |
| <dependency> |
| <groupId>org.eclipse.jetty</groupId> |
| <artifactId>jetty-ant</artifactId> |
| </dependency> |
| ]]> |
| </script></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="jetty-ant-preparation"></a>Preparing Your Project</h3></div></div></div><p>To set up your project for Ant to run Jetty, you need a Jetty distribution and the jetty-ant Jar:</p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem"><p><a class="link" href="http://download.eclipse.org/jetty/" target="_top">Download</a> a Jetty |
| distribution and unpack it in the local filesystem.</p></li><li class="listitem"><p><a class="link" href="http://central.maven.org/maven2/org/eclipse/jetty/jetty-ant/" target="_top">Get</a> |
| the jetty-ant Jar.</p></li><li class="listitem"><p>Make a directory in your project called |
| <code class="filename">jetty-lib/</code>.</p></li><li class="listitem"><p>Copy all of the Jars in your Jetty distribution's <code class="filename">lib</code> directory, |
| and all its subdirectories, into your new <code class="filename">jetty-lib</code> dir. |
| When copying the Jars, <span class="emphasis"><em>don't</em></span> preserve the Jetty |
| distribution's lib dir hierarchy – all the jars should be directly |
| inside your <code class="filename"> jetty-lib</code> dir.</p></li><li class="listitem"><p>Also copy the jetty-ant Jar you downloaded earlier into the |
| <code class="filename">jetty-lib</code> dir.</p></li><li class="listitem"><p>Make a directory in your project called |
| <code class="filename">jetty-temp</code>.</p></li></ol></div><p>Now you're ready to edit or create your Ant |
| <code class="filename">build.xml</code> file.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="d0e17832"></a>Preparing the <code class="filename">build.xml</code> file</h3></div></div></div><p>Begin with an empty <code class="filename">build.xml</code>:</p><div class="informalexample"><script type="syntaxhighlighter" class="brush: xml;toolbar: false"> |
| <![CDATA[ |
| <project name="Jetty-Ant integration test" basedir="."> |
| </project> |
| ]]> |
| </script></div><p>Add a <code class="code"><taskdef></code> that imports |
| all available Jetty tasks:</p><div class="informalexample"><script type="syntaxhighlighter" class="brush: xml;toolbar: false"> |
| <![CDATA[ |
| <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> |
| ]]> |
| </script></div><p>Now you are ready to add a new target for running Jetty:</p><div class="informalexample"><script type="syntaxhighlighter" class="brush: xml;toolbar: false"> |
| <![CDATA[ |
| <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.run /> |
| </target> |
| |
| </project> |
| ]]> |
| </script></div><p>This is the minimal configuration you need. You can now start Jetty on |
| the default port of 8080.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="d0e17861"></a>Starting Jetty via Ant</h3></div></div></div><p>At the command line enter:</p><div class="screenexample"><pre class="screen">> ant jetty.run</pre></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="d0e17868"></a>Configuring the Jetty Container</h3></div></div></div><p>A number of configuration options can help you set |
| up the Jetty environment so that your web application has all the |
| resources it needs:</p><div class="variablelist"><dl><dt><span class="term">ports and connectors:</span></dt><dd><p>To configure the port that Jetty starts on you need to define a connector. First you need to configure a |
| <code class="code"><typedef></code> for the Connector class and then define |
| the connector in the Jetty tags: </p><div class="informalexample"><script type="syntaxhighlighter" class="brush: xml;toolbar: false"> |
| <![CDATA[ |
| <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" /> |
| |
| <typedef name="connector" classname="org.eclipse.jetty.ant.types.Connector" |
| classpathref="jetty.plugin.classpath" loaderref="jetty.loader" /> |
| |
| <target name="jetty.run"> |
| <jetty.run> |
| <connectors> |
| <connector port="8090"/> |
| </connectors> |
| </jetty.run> |
| </target> |
| |
| </project> |
| ]]> |
| </script></div><p> </p><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title"><i class="icon-lightbulb"></i> Tip</h3><p>You can set the port to 0, which starts the Jetty |
| server connector on an arbitrary available port. You can then |
| access these values from system properties |
| <code class="code">jetty.ant.server.port</code> and |
| <code class="code">jetty.ant.server.host</code>.</p></div></dd><dt><span class="term">login services:</span></dt><dd><p>If your web application requires authentication and |
| authorization services, you can configure these on the Jetty |
| container. Here's an example of how to set up an <a class="link" href="http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/security/HashLoginService.html" target="_top"> |
| org.eclipse.jetty.security.HashLoginService</a>:</p><div class="informalexample"><script type="syntaxhighlighter" class="brush: xml;toolbar: false"> |
| <![CDATA[ |
| <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" /> |
| |
| <typedef name="hashLoginService" classname="org.eclipse.jetty.security.HashLoginService" |
| classpathref="jetty.plugin.classpath" loaderref="jetty.loader" /> |
| |
| <target name="jetty.run"> |
| <jetty.run> |
| <loginServices> |
| <hashLoginService name="Test Realm" config="${basedir}/realm.properties"/> |
| </loginServices> |
| </jetty.run> |
| </target> |
| |
| </project> |
| ]]> |
| </script></div></dd><dt><span class="term">request log:</span></dt><dd><p>The <code class="code">requestLog</code> option allows you to specify a |
| request logger for the Jetty instance. You can either use the <a class="link" href="http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/server/NCSARequestLog.html" target="_top"> |
| org.eclipse.jetty.server.NCSARequestLog</a> class, or supply the |
| name of your custom class:</p><div class="informalexample"><script type="syntaxhighlighter" class="brush: xml;toolbar: false"> |
| <![CDATA[ |
| <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.run requestLog="com.acme.MyFancyRequestLog"> |
| </jetty.run> |
| </target> |
| |
| </project> |
| ]]> |
| </script></div></dd><dt><span class="term">temporary directory:</span></dt><dd><p>You can configure a directory as a temporary file |
| store for uses such as expanding files and compiling JSPs by supplying the |
| <code class="code">tempDirectory</code> option:</p><div class="informalexample"><script type="syntaxhighlighter" class="brush: xml;toolbar: false"> |
| <![CDATA[ |
| <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.run tempDirectory="${basedir}/jetty-temp"> |
| </jetty.run> |
| </target> |
| |
| </project> |
| ]]> |
| </script></div></dd><dt><span class="term">other context handlers:</span></dt><dd><p>You may need to configure some other context |
| handlers to run at the same time as your web application. You can specify these |
| other context handlers using the <code class="code"> |
| <contextHandlers></code> element. You need to supply a |
| <code class="code"><typedef></code> for it before you can use it:</p><div class="informalexample"><script type="syntaxhighlighter" class="brush: xml;toolbar: false"> |
| <![CDATA[ |
| <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" /> |
| |
| <typedef name="contextHandlers" classname="org.eclipse.jetty.ant.types.ContextHandlers" |
| classpathref="jetty.plugin.classpath" loaderref="jetty.loader" /> |
| |
| <target name="jetty.run"> |
| <jetty.run> |
| <contextHandlers> |
| <contextHandler resourceBase="${basedir}/stuff" contextPath="/stuff"/> |
| </contextHandlers> |
| </jetty.run> |
| </target> |
| |
| </project> |
| ]]> |
| </script></div></dd><dt><span class="term">system properties:</span></dt><dd><p>As a convenience, you can configure system properties by using |
| the <code class="code"> <systemProperties></code> element. Be aware |
| that, depending on the purpose of the system property, setting it |
| from within the Ant execution may mean that it is evaluated too late, |
| as the JVM evaluates some system properties on entry.</p><div class="informalexample"><script type="syntaxhighlighter" class="brush: xml;toolbar: false"> |
| <![CDATA[ |
| <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.run> |
| <systemProperties> |
| <systemProperty name="foo" value="bar"/> |
| </systemProperties> |
| </jetty.run> |
| </target> |
| |
| </project> |
| ]]> |
| </script></div></dd><dt><span class="term">jetty XML file:</span></dt><dd><p>If you have a lot of configuration to apply to the Jetty |
| container, it can be more convenient to put it into a standard Jetty |
| XML configuration file and have the Ant plugin apply it before |
| starting Jetty:</p><div class="informalexample"><script type="syntaxhighlighter" class="brush: xml;toolbar: false"> |
| <![CDATA[ |
| <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.run jettyXml="${basedir}/jetty.xml"> |
| </jetty.run> |
| </target> |
| |
| </project> |
| ]]> |
| </script></div></dd><dt><span class="term">scanning for changes:</span></dt><dd><p>The most useful mode in which to run the Ant plugin is for it |
| to continue to execute Jetty and automatically restart your web |
| application if any part of it changes (for example, your IDE |
| recompiles the classes of the web application). The |
| <code class="code">scanIntervalSeconds</code> option controls how frequently the |
| <code class="code"><jetty.run></code> task scans your web |
| application/WAR file for changes. The default value of |
| <code class="code">0</code> disables scanning. Here's an example where Jetty checks for changes every five seconds:</p><div class="informalexample"><script type="syntaxhighlighter" class="brush: xml;toolbar: false"> |
| <![CDATA[ |
| <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.run scanIntervalSeconds="5"> |
| </jetty.run> |
| </target> |
| |
| </project> |
| ]]> |
| </script></div></dd><dt><span class="term">stopping:</span></dt><dd><p>In normal mode (<code class="code">daemon="false"</code>), |
| the <code class="code"><jetty.run></code> task runs until you |
| <code class="code">cntrl-c</code> it. It may be useful to |
| script both the stop AND the start of Jetty. For such a case, we |
| provide the <code class="code"><jetty.stop></code> task.</p><p>To use it, you need to provide a port and an |
| identifying string to both the <code class="code"> <jetty.run></code> and |
| the <code class="code"><jetty.stop></code> tasks, where |
| <code class="code"><jetty.run></code> listens on the given port for a |
| stop message containing the given string, and cleanly stops Jetty |
| when it is received. The <code class="code"><jetty.stop></code> task sends |
| this stop message. You can also optionally provide a |
| <code class="code">stopWait</code> value (in seconds), which is the length |
| of time the <code class="code"> <jetty.stop></code> task waits for |
| confirmation that the stop succeeded:</p><div class="informalexample"><script type="syntaxhighlighter" class="brush: xml;toolbar: false"> |
| <![CDATA[ |
| <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.run stopPort="9999" stopKey="9999"> |
| </jetty.run> |
| </target> |
| |
| <target name="jetty.stop"> |
| <jetty.stop stopPort="9999" stopKey="9999" stopWait="10"/> |
| </target> |
| |
| </project> |
| ]]> |
| </script></div><p>To stop jetty via Ant, enter:</p><div class="screenexample"><pre class="screen"> |
| > ant jetty.stop |
| </pre></div></dd><dt><span class="term">execution without pausing ant:</span></dt><dd><p>Usually, the <code class="code"><jetty.run></code> task runs |
| until you <code class="code">cntrl-c</code> it, pausing the execution of Ant as |
| it does so. In some cases, it may be useful to let Ant continue |
| executing. For example, to run your unit tests you may need other tasks to execute while |
| Jetty is running. For this case, we |
| provide the <code class="code">daemon</code> option. This defaults to |
| <code class="code">false</code>. For <code class="code">true</code>, Ant continues |
| to execute after starting Jetty. If Ant exits, so does Jetty. Understand |
| that this option does <span class="emphasis"><em>not</em></span> fork a new process |
| for Jetty.</p><div class="informalexample"><script type="syntaxhighlighter" class="brush: xml;toolbar: false"> |
| <![CDATA[ |
| <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.run daemon="true"> |
| </jetty.run> |
| </target> |
| |
| </project> |
| ]]> |
| </script></div></dd></dl></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="d0e18061"></a>Deploying a Web Application</h3></div></div></div><p>Add a <code class="code"><typedef></code> for the |
| <code class="code">org.eclipse.jetty.ant.AntWebAppContext</code> class with name <span class="emphasis"><em>webApp</em></span>, then add a |
| <code class="code"><webApp></code> element to <code class="code"><jetty.run></code> to |
| describe your web application. The following example deploys a web |
| application that is expanded in the local directory <code class="code">foo/</code> to |
| context path <code class="code"> / </code>:</p><div class="informalexample"><script type="syntaxhighlighter" class="brush: xml;toolbar: false"> |
| <![CDATA[ |
| <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" /> |
| |
| <typedef name="webApp" classname="org.eclipse.jetty.ant.AntWebAppContext" |
| classpathref="jetty.plugin.classpath" loaderref="jetty.loader" /> |
| |
| <target name="jetty.run"> |
| <jetty.run> |
| <webApp war="${basedir}/foo" contextPath="/"/> |
| </jetty.run> |
| </target> |
| |
| </project> |
| ]]> |
| </script></div><div class="variablelist"><dl><dt><span class="term">deploying a WAR file:</span></dt><dd><p>It is not necessary to expand the web application into a directory. It is fine to deploy it as a |
| WAR file:</p><div class="informalexample"><script type="syntaxhighlighter" class="brush: xml;toolbar: false"> |
| <![CDATA[ |
| <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" /> |
| |
| <typedef name="webApp" classname="org.eclipse.jetty.ant.AntWebAppContext" |
| classpathref="jetty.plugin.classpath" loaderref="jetty.loader" /> |
| |
| <target name="jetty.run"> |
| <jetty.run> |
| <webApp war="${basedir}/foo.war" contextPath="/"/> |
| </jetty.run> |
| </target> |
| |
| </project> |
| ]]> |
| </script></div></dd><dt><span class="term">deploying more than one web application:</span></dt><dd><p>You can also deploy more than one web application:</p><div class="informalexample"><script type="syntaxhighlighter" class="brush: xml;toolbar: false"> |
| <![CDATA[ |
| <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" /> |
| |
| <typedef name="webApp" classname="org.eclipse.jetty.ant.AntWebAppContext" |
| classpathref="jetty.plugin.classpath" loaderref="jetty.loader" /> |
| |
| <target name="jetty.run"> |
| <jetty.run> |
| <webApp war="${basedir}/foo.war" contextPath="/"/> |
| <webApp war="${basedir}/other contextPath="/other"/> |
| <webApp war="${basedir}/bar.war" contextPath="/bar"/> |
| </jetty.run> |
| </target> |
| |
| </project> |
| ]]> |
| </script></div></dd></dl></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="d0e18109"></a>Configuring the Web Application</h4></div></div></div><p>As the <code class="code">org.eclipse.jetty.ant.AntWebAppContext</code> class is an |
| extension of the <a class="link" href="http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/webapp/WebAppContext.html" target="_top"><code class="code">org.eclipse.jetty.webapp.WebAppContext</code></a> |
| class, you can configure it by adding attributes of the same name |
| (without the <code class="code">set</code> or <code class="code">add</code> prefix) as the setter methods.</p><p>Here's an example that specifies the location of the |
| <code class="code">web.xml</code> file (equivalent to method <a class="link" href="http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/webapp/WebAppContext.html#setDescriptor%28java.lang.String%29" target="_top"><code class="code">AntWebAppContext.setDescriptor()</code></a>) |
| and the web application's temporary directory (equivalent to method |
| <a class="link" href="http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/webapp/WebAppContext.html#setTempDirectory%28java.io.File%29" target="_top"><code class="code">AntWebAppContext.setTempDirectory()</code></a>):</p><div class="informalexample"><script type="syntaxhighlighter" class="brush: xml;toolbar: false"> |
| <![CDATA[ |
| <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" /> |
| |
| <typedef name="webApp" classname="org.eclipse.jetty.ant.AntWebAppContext" |
| classpathref="jetty.plugin.classpath" loaderref="jetty.loader" /> |
| |
| <target name="jetty.run"> |
| <jetty.run> |
| <webApp descriptor="${basedir}/web.xml" tempDirectory="${basedir}/my-temp" war="${basedir}/foo" contextPath="/"/> |
| </jetty.run> |
| </target> |
| |
| </project> |
| ]]> |
| </script></div><p>Other extra configuration options for the |
| AntWebAppContext include:</p><div class="variablelist"><dl><dt><span class="term">extra classes and Jars:</span></dt><dd><p>If your web application's classes and Jars do not reside |
| inside <code class="filename">WEB-INF</code> of the resource base directory, you can use |
| the <classes> and <jar> elements to tell Ant where to |
| find them. Here's an example:</p><div class="informalexample"><script type="syntaxhighlighter" class="brush: xml;toolbar: false"> |
| <![CDATA[ |
| <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" /> |
| |
| <typedef name="webApp" classname="org.eclipse.jetty.ant.AntWebAppContext" |
| classpathref="jetty.plugin.classpath" loaderref="jetty.loader" /> |
| |
| <target name="jetty.run"> |
| <jetty.run> |
| <webApp descriptor="${basedir}/web.xml" tempDirectory="${basedir}/my-temp" war="${basedir}/foo" contextPath="/"> |
| <classes dir="${basedir}/classes"> |
| <include name="**/*.class"/> |
| <include name="**/*.properties"/> |
| </classes> |
| <lib dir="${basedir}/jars"> |
| <include name="**/*.jar"/> |
| <exclude name="**/*.dll"/> |
| </lib> |
| </webApp> |
| </jetty.run> |
| </target> |
| |
| </project> |
| ]]> |
| </script></div></dd><dt><span class="term">context attributes:</span></dt><dd><p>Jetty allows you to set up ServletContext attributes on your |
| web application. You configure them in a context XML file that |
| is applied to your WebAppContext instance prior to starting it. |
| For convenience, the Ant plugin permits you to configure these |
| directly in the build file. Here's an example:</p><div class="informalexample"><script type="syntaxhighlighter" class="brush: xml;toolbar: false"> |
| <![CDATA[ |
| <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" /> |
| |
| <typedef name="webApp" classname="org.eclipse.jetty.ant.AntWebAppContext" |
| classpathref="jetty.plugin.classpath" loaderref="jetty.loader" /> |
| |
| <target name="jetty.run"> |
| <jetty.run> |
| <webApp war="${basedir}/foo" contextPath="/"> |
| <attributes> |
| <attribute name="my.param" value="123"/> |
| </attributes> |
| </webApp> |
| </jetty.run> |
| </target> |
| |
| </project> |
| ]]> |
| </script></div></dd><dt><span class="term"><code class="filename">jetty-env.xml</code> file:</span></dt><dd><p>If you are using features such as <a class="link" href="">JNDI</a> with your web application, |
| you may need to configure a <a class="link" href=""><code class="filename">WEB-INF/jetty-env.xml</code></a> file to |
| define resources. If the structure of your web application project |
| is such that the source of <code class="filename">jetty-env.xml</code> file resides |
| somewhere other than <code class="filename">WEB-INF</code>, you can use the <code class="code"> |
| jettyEnvXml</code> attribute to tell Ant where to find it:</p><div class="informalexample"><script type="syntaxhighlighter" class="brush: xml;toolbar: false"> |
| <![CDATA[ |
| <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" /> |
| |
| <typedef name="webApp" classname="org.eclipse.jetty.ant.AntWebAppContext" |
| classpathref="jetty.plugin.classpath" loaderref="jetty.loader" /> |
| |
| <target name="jetty.run"> |
| <jetty.run> |
| <webApp war="${basedir}/foo" contextPath="/" jettyEnvXml="${basedir}/jetty-env.xml"> |
| <attributes> |
| </webApp> |
| </jetty.run> |
| </target> |
| |
| </project> |
| ]]> |
| </script></div></dd><dt><span class="term">context XML file:</span></dt><dd><p>You may prefer or even require to do some advanced |
| configuration of your web application outside of the Ant build |
| file. In this case, you can use a standard context XML |
| configuration file which the Ant plugin applies to your web |
| application before it is deployed. Be aware that the settings from the |
| context XML file <span class="emphasis"><em>override</em></span> those of the |
| attributes and nested elements you defined in the build |
| file.</p><div class="informalexample"><script type="syntaxhighlighter" class="brush: xml;toolbar: false"> |
| <![CDATA[ |
| 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" /> |
| |
| <typedef name="webApp" classname="org.eclipse.jetty.ant.AntWebAppContext" |
| classpathref="jetty.plugin.classpath" loaderref="jetty.loader" /> |
| |
| <target name="jetty.run"> |
| <jetty.run> |
| <webApp war="${basedir}/foo" contextPath="/" contextXml="${basedir}/jetty-env.xml"> |
| <attributes> |
| </webApp> |
| </jetty.run> |
| </target> |
| |
| </project> |
| ]]> |
| </script></div></dd></dl></div></div></div></div></div><script type="text/javascript"> |
| SyntaxHighlighter.all() |
| </script><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="jetty-jspc-maven-plugin.html"><i class="icon-chevron-left"></i> Previous</a> </td><td width="20%" align="center"><a accesskey="u" href="development.html"><i class="icon-chevron-up"></i> Top</a></td><td width="40%" align="right"> <a accesskey="n" href="jetty-handlers.html">Next <i class="icon-chevron-right"></i></a></td></tr><tr><td width="40%" align="left" valign="top">Jetty Jspc Maven Plugin </td><td width="20%" align="center"><a accesskey="h" href="index.html"><i class="icon-home"></i> Home</a></td><td width="40%" align="right" valign="top"> Chapter 23. Handlers</td></tr></table></div><p xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><div class="jetty-callout"> |
| See an error or something missing? |
| <span class="callout"><a href="http://github.com/jetty-project/jetty-documentation">Contribute to this documentation at |
| <span class="website"><i class="icon-github"></i> Github!</span></a></span><span style="float: right"><i>(Generated: 2015-06-15T13:18:29-05:00)</i></span></div></p><script xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" type="text/javascript"> |
| var _gaq = _gaq || []; |
| _gaq.push(['_setAccount', 'UA-1149868-7']); |
| _gaq.push(['_trackPageview']); |
| |
| (function() { |
| var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; |
| ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; |
| var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); |
| })(); |
| </script></body></html> |