Jump to: navigation, search

Difference between revisions of "Jetty/Howto/Use Jetty with Ant"

< Jetty‎ | Howto
m (New page: {{Jetty Howto | introduction A new plugin is available in the /extras/ant location, which makes it possible to start a Jetty web server directly from the Ant build script, and, to embed t...)
 
(18 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Jetty Howto
+
{{Jetty Howto
| introduction
+
| introduction =
A new plugin is available in the /extras/ant location, which 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 a tight integration with the build system.
+
The Ant Jetty plugin is in the [http://git.codehaus.org/gitweb.cgi?p=jetty-project.git;a=summary codehouse trunk] in the <tt>jetty-ant</tt> 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 a tight integration with the build system.
  
For impatient folks, there is already a [http://svn.codehaus.org/jetty-contrib/trunk/jetty-ant-demo/ demo provided in jetty-contrib repository] for the Ant Jetty plugin. It's good to compile Jetty 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 [http://maven.apache.org/guides/mini/guide-mirror-settings.html Maven repositories]. Please see build.xml file in jetty-ant-demo folder for a list of required JARs.
 
  
Modifying build.xml from jetty-ant-demo is also the easiest way to start playing with this plugin.
+
}}
 +
==Preparation==
  
==Beginning To Use Ant==
+
You will need a [http://download.eclipse.org/jetty/ jetty distribution] and the [http://repo1.maven.org/maven2/org/mortbay/jetty/jetty-ant/ jetty-ant jar] in order to set up your project for ant to run jetty:
  
The Ant plugin depends on Jetty JARs, and so far it's necessary to build Jetty and then the Ant plugin directly from sources. Here's how it goes:
+
# Get a [http://download.eclipse.org/jetty/ jetty distribution] and unpack it the local filesystem
 +
# Get the [http://repo1.maven.org/maven2/org/mortbay/jetty/jetty-ant/ jetty-ant jar]
 +
# Make a directory in your project called <tt>jetty-lib/</tt>
 +
# Copy all of the jars in your jetty distribution's <tt>lib</tt> directory, and all its subdirectories, into your new <tt>jetty-lib</tt> dir. When copying the jars, DON'T preserve the jetty distro's <tt>lib</tt> dir hierarchy - all the jars should be directly inside your <tt>jetty-lib</tt> dir.
 +
# Also copy the [http://repo1.maven.org/maven2/org/mortbay/jetty/jetty-ant/ jetty-ant jar]  you downloaded earlier into the <tt>jetty-lib</tt> dir.
 +
# Make a directory in your project called <tt>jetty-temp</tt>
  
# Get the latest jetty sources from http://dist.codehaus.org/jetty/
+
Now you're ready to edit or create your Ant build.xml file.
# Unpack jetty and build it with 'mvn install' (If you don't have Maven yet, get it from http://maven.apache.org/)
+
# Go to the extras/ant/ folder and build ant plugin with 'mvn install'
+
# Go to <your M2 repo root>/repository/org/eclipse/jetty/jetty-ant and grab the jetty-ant plugin JAR.
+
# Get these files to run Jetty with JSP/Servlets support (find these in <your M2 repo root>/repository/org/eclipse/jetty):
+
#* 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/
+
# Put all the JARs inside one lib directory (let's say jetty-lib).
+
  
 
==Preparing the <tt>build.xml file</tt>==
 
==Preparing the <tt>build.xml file</tt>==
  
Let's start with an empty build.xml  
+
Let's start with an empty <tt>build.xml</tt>:
  
 
<source lang="xml">
 
<source lang="xml">
Line 35: Line 27:
 
</source>
 
</source>
  
Then, you must define a ''jetty'' task:  
+
Then, you must define a <tt>jetty</tt> task:  
  
 
<source lang="xml">
 
<source lang="xml">
Line 46: Line 38:
 
</source>
 
</source>
  
Now, we are ready to add a new target with Jetty container declaration:
+
Now you are ready to add a new target with Jetty container declaration:
  
 
<source lang="xml">
 
<source lang="xml">
Line 61: Line 53:
 
</source>
 
</source>
  
Starting jetty on port 8080 is then a simple matter of executing ''ant jetty.run'' from the command line.
+
This is the minimal configuration need. You can now start jetty.
 +
 
 +
==Starting Jetty via Ant==
 +
At the command line do:
 +
 
 +
<tt>
 +
ant jetty.run
 +
</tt>
  
 
==Deploying web applications==
 
==Deploying 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.  
+
To add web applications to the Jetty web server, now put extra <tt>webapp</tt> tags inside <tt>jetty</tt> tag. Notice, that a <tt>tempDirectory</tt> attribute has been added to the <tt>jetty</tt> task to specify where temporary files are stored.  
  
 
<source lang="xml">  
 
<source lang="xml">  
Line 80: Line 79:
 
   </target>
 
   </target>
 
</project>
 
</project>
 
 
</source>
 
</source>
  
You can put many ''webapp'' tags inside ''jetty'' tag, thus deploying many web applications simultaneously.
+
You can put many <tt>webapp</tt> tags inside <tt>jetty</tt> tag, thus deploying many web applications simultaneously.
 +
 
 +
===A Special Note on Using JSPs with JSTL Or Other Taglibs ===
 +
 
 +
If your webapp uses a taglib that should be found on the container classpath (such as JSTL) you will need to pass in some extra information to the webapp to tell jetty which container jars can contain the taglibs. This is defined as a set of jar name patterns.
 +
 
 +
If you are using JSTL, and are using the jars provided by the standard jetty distribution, the JSTL taglibs are located in the jar named something like <tt>org.apache.taglibs.standard.glassfish_1.2.0.xxxx.jar</tt> (where xxx is replaced by a specific version number).
 +
 
 +
The following pattern defines all jars that contain the string "jsp-api" or "jsp" or "taglibs" as jars that will be searched at runtime for taglibs:
 +
 
 +
<tt>.*/.*jsp-api-[^/]*\.jar$|.*/.*jsp-[^/]*\.jar$|.*/.*taglibs[^/]*\.jar$</tt>
 +
 
 +
 
 +
This pattern should be added to your <webApp/> declaration as the value of a context attribute named <tt>org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern</tt>. Here's how the modified build.xml file looks now:
 +
 
 +
<source lang="xml">
 +
<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">
 +
        <attributes>
 +
          <attribute name="org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern" value=".*/.*jsp-api-[^/]*\.jar$|.*/.*jsp-[^/]*\.jar$|.*/.*taglibs[^/]*\.jar$"/>
 +
        </attributes>
 +
      </webApp>
 +
    </jetty>
 +
  </target>
 +
</project>
 +
</source>
  
 
==Plugin syntax==
 
==Plugin syntax==
  
====There are many ways to configure ''jetty'' task:====
+
====There are many ways to configure <tt>jetty</tt> tasks:====
  
* ''tempDirectory'' - specifies the Jetty temporary web directory: <div class="code panel" style="border-width: 1px"><div class="codeContent panelContent">  
+
* <tt>tempDirectory</tt>–specifies the Jetty temporary web directory:  
 +
<source lang="xml">
 
  <jetty tempDirectory="jetty-temp" />
 
  <jetty tempDirectory="jetty-temp" />
</div></div><br class="atl-forced-newline" /><br class="atl-forced-newline" /><br class="atl-forced-newline" /><br class="atl-forced-newline" />
+
</source>
* ''requestLog'' - defines a request logger: <div class="code panel" style="border-width: 1px"><div class="codeContent panelContent">  
+
* <tt>requestLog</tt>–defines a request logger:  
 +
<source lang="xml">  
 
  <jetty ... requestLog="your.fancy.request.logger"/>
 
  <jetty ... requestLog="your.fancy.request.logger"/>
</div></div><br class="atl-forced-newline" /><br class="atl-forced-newline" /><br class="atl-forced-newline" /><br class="atl-forced-newline" />
+
</source>
* ''jettyXml'' - applies additional configuration via a standard jetty.xml file: <div class="code panel" style="border-width: 1px"><div class="codeContent panelContent">  
+
* <tt>jettyXml</tt>–applies additional configuration via a standard <tt>jetty.xml</tt> file:  
 +
<source lang="xml">  
 
  <jetty ... jettyXml="path/to/jetty.xml"/>
 
  <jetty ... jettyXml="path/to/jetty.xml"/>
</div></div><br class="atl-forced-newline" /><br class="atl-forced-newline" /><br class="atl-forced-newline" /><br class="atl-forced-newline" />
+
</source>
* ''systemProperties'' - adds system properties when starting Jetty: <div class="code panel" style="border-width: 1px"><div class="codeContent panelContent">  
+
* <tt>systemProperties</tt>–adds system properties when starting Jetty:  
 +
<source lang="xml">  
 
  <jetty ...>
 
  <jetty ...>
 
   <systemProperties>
 
   <systemProperties>
Line 104: Line 138:
 
   </systemProperties>
 
   </systemProperties>
 
  </jetty>
 
  </jetty>
</div></div><br class="atl-forced-newline" /><br class="atl-forced-newline" /><br class="atl-forced-newline" /><br class="atl-forced-newline" />
+
</source>
* ''connectors'' - defines Jetty connectors (a better way still needs to be developed): <div class="code panel" style="border-width: 1px"><div class="codeContent panelContent">  
+
* <tt>connectors</tt>–defines Jetty connectors:  
  <typedef name="selectChannelConnector" classname="org.mortbay.jetty.nio.SelectChannelConnector"
+
<source lang="xml">  
 +
  <typedef name="selectChannelConnector" classname="org.eclipse.jetty.nio.SelectChannelConnector"
 
                             classpathref="jetty.plugin.classpath" loaderref="jetty.loader" />
 
                             classpathref="jetty.plugin.classpath" loaderref="jetty.loader" />
 
  ...
 
  ...
Line 114: Line 149:
 
   </connectors>
 
   </connectors>
 
  </jetty>
 
  </jetty>
</div></div><br class="atl-forced-newline" /><br class="atl-forced-newline" /><br class="atl-forced-newline" />
+
</source>  
* <div class="code panel" style="border-width: 1px"><div class="codeContent panelContent">
+
* <tt>loginServices</tt> - adds authentication via user "realms":  
+
<source lang="xml">>  
</div></div><br class="atl-forced-newline" /><br class="atl-forced-newline" /><br class="atl-forced-newline" /><br class="atl-forced-newline" />
+
  <typedef name="hashLoginService" classname="org.eclipse.jetty.security.HashLoginService"
* ''userRealms'' - adds authentication via user "realms": <div class="code panel" style="border-width: 1px"><div class="codeContent panelContent">  
+
  <typedef name="jdbcRealm" classname="org.mortbay.jetty.security.HashUserRealm"
+
 
                   classpathref="jetty.plugin.classpath" loaderref="jetty.loader" />
 
                   classpathref="jetty.plugin.classpath" loaderref="jetty.loader" />
 
  ...
 
  ...
 
  <jetty ...>
 
  <jetty ...>
   <userRealms>
+
   <loginServices>
     <userRealm name="realm1" config="path/to/realm/config" />
+
     <hashLoginService name="realm1" config="path/to/realm/config" />
   </userRealms>
+
   </loginServices>
 
  </jetty>
 
  </jetty>
</div></div><br class="atl-forced-newline" /><br class="atl-forced-newline" /><br class="atl-forced-newline" />
+
</source>
* <div class="code panel" style="border-width: 1px"><div class="codeContent panelContent">
+
+
</div></div><br class="atl-forced-newline" /><br class="atl-forced-newline" /><br class="atl-forced-newline" /><br class="atl-forced-newline" />
+
  
====There are also many ways to configure web applications with ''webapp'' tag:====
+
====There are also many ways to configure web applications with <tt>webapp</tt> tag:====
  
* ''name'' - name of a web application, which is used by DefaultServlet to display application description <div class="code panel" style="border-width: 1px"><div class="codeContent panelContent">  
+
* <tt>name</tt>–name of a web application, which is used by <tt>DefaultServlet</tt> to display application description:  
 +
<source lang="xml">  
 
  <jetty ...>
 
  <jetty ...>
 
   <webapp name="name" .../>
 
   <webapp name="name" .../>
 
  </jetty>
 
  </jetty>
</div></div><br class="atl-forced-newline" /><br class="atl-forced-newline" /><br class="atl-forced-newline" /><br class="atl-forced-newline" />
+
</source>
* ''warfile'' - path to .war file or a directory with web application contents: <div class="code panel" style="border-width: 1px"><div class="codeContent panelContent">  
+
* <tt>warfile</tt>–path to .war file or a directory with web application contents:  
 +
<source lang="xml">  
 
  <jetty ...>
 
  <jetty ...>
 
   <webapp warfile="/path/to/war/file/or/web/application/contents" .../>
 
   <webapp warfile="/path/to/war/file/or/web/application/contents" .../>
 
  </jetty>
 
  </jetty>
</div></div><br class="atl-forced-newline" /><br class="atl-forced-newline" /><br class="atl-forced-newline" /><br class="atl-forced-newline" />
+
</source>
* ''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): <div class="code panel" style="border-width: 1px"><div class="codeContent panelContent">  
+
* <tt>contextPath</tt>–a context path a particular web application will be deployed to, and thus where it will be accessible (<nowiki>http://localhost:8080/webapp</nowiki> in this case):  
 +
<source lang="xml">  
 
  <jetty ...>
 
  <jetty ...>
 
   <webapp contextPath="/webapp" .../>
 
   <webapp contextPath="/webapp" .../>
 
  </jetty>
 
  </jetty>
</div></div><br class="atl-forced-newline" /><br class="atl-forced-newline" /><br class="atl-forced-newline" /><br class="atl-forced-newline" />
+
</source>
* ''jettyEnvXml'' - path to [http://docs.codehaus.org/display/JETTY/jetty-env.xml jettyEnv.xml file with JNDI resource declarations]<div class="code panel" style="border-width: 1px"><div class="codeContent panelContent">  
+
* <tt>jettyEnvXml</tt>–path to [[Jetty/Reference/jetty-env.xml|jettyEnv.xml file with JNDI resource declarations]]:
 +
<source lang="xml">  
 
  <jetty ...>
 
  <jetty ...>
 
   <webapp jettyEnvXml="/path/to/jettyEnv.xml" .../>
 
   <webapp jettyEnvXml="/path/to/jettyEnv.xml" .../>
 
  </jetty>
 
  </jetty>
</div></div><br class="atl-forced-newline" /><br class="atl-forced-newline" /><br class="atl-forced-newline" /><br class="atl-forced-newline" />
+
</source>
* ''webXml'' - path to web.xml file. If not specified, the default (location-of-war-file/WEB-INF/web.xml) location is used: <div class="code panel" style="border-width: 1px"><div class="codeContent panelContent">  
+
* <tt>webXml</tt>–path to <tt>web.xml</tt> file. If not specified, the default (<tt>location-of-war-file/WEB-INF/web.xml</tt>) location is used:  
 +
<source lang="xml">  
 
  <jetty ...>
 
  <jetty ...>
 
   <webapp webXmlFile="/path/to/web/xml" .../>
 
   <webapp webXmlFile="/path/to/web/xml" .../>
 
  </jetty>
 
  </jetty>
</div></div><br class="atl-forced-newline" /><br class="atl-forced-newline" /><br class="atl-forced-newline" /><br class="atl-forced-newline" />
+
</source>
* ''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.<br />'''IMPORTANT'''<nowiki>: Please note, that all files included with <classes/> or <lib/> tags are </nowiki>'''automatically''' scanned for changes if you provide ''scanIntervalSeconds'' parameter in the <jetty/> tag. There's no need to add them using the <scanTargets/> section. <div class="code panel" style="border-width: 1px"><div class="codeContent panelContent">  
+
* <tt>scanTargets</tt> and <tt>scanIntervalSeconds</tt>–points to special files/folders that need to be scanned, and specifies scanner interval in seconds. If any of the files changes, the web application is automatically reloaded. You can adjust interval and scanned files per web application.
 +
 
 +
{{note|All files included with <classes/> or <lib/> tags are ''automatically'' scanned for changes if you provide <tt>scanIntervalSeconds</tt> parameter in the <tt><jetty/></tt> tag. There's no need to add them using the <tt><scanTargets/></tt> section.}}
 +
<source lang="xml">
 
  <jetty ...>
 
  <jetty ...>
 
   <webapp ... scanIntervalSeconds="5">
 
   <webapp ... scanIntervalSeconds="5">
Line 167: Line 205:
 
   </webapp>
 
   </webapp>
 
  </jetty>
 
  </jetty>
</div></div><br class="atl-forced-newline" /><br class="atl-forced-newline" /><br class="atl-forced-newline" /><br class="atl-forced-newline" />
+
</source>
* ''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. <div class="code panel" style="border-width: 1px"><div class="codeContent panelContent">  
+
* <tt>lib</tt>–specifies which libraries need be included for a particular web application (treated as files inside WEB-INF/lib folder). Multiple <tt>lib</tt> tags are allowed.  
 +
<source lang="xml">  
 
  <jetty ...>
 
  <jetty ...>
 
   <webapp ...>
 
   <webapp ...>
Line 174: Line 213:
 
   </webapp>
 
   </webapp>
 
  </jetty>
 
  </jetty>
</div></div><br class="atl-forced-newline" /><br class="atl-forced-newline" /><br class="atl-forced-newline" /><br class="atl-forced-newline" />
+
</source>
* ''classes'' - specifies which folder contains web application classes (treated as WEB-INF/classes folder). Multiple ''classes'' tags are allowed. <div class="code panel" style="border-width: 1px"><div class="codeContent panelContent">  
+
* <tt>classes</tt>–specifies which folder contains web application classes (treated as <tt>WEB-INF/classes</tt> folder). Multiple <tt>classes</tt> tags are allowed.  
 +
<source lang="xml">  
 
  <jetty ...>
 
  <jetty ...>
 
   <webapp ...>
 
   <webapp ...>
Line 181: Line 221:
 
   </webapp>
 
   </webapp>
 
  </jetty>
 
  </jetty>
</div></div><br class="atl-forced-newline" /><br class="atl-forced-newline" /><br class="atl-forced-newline" /><br class="atl-forced-newline" />
+
</source>
* ''connectors'' - specifies additional web application connectors
+
* <tt>connectors</tt>–specifies additional web application connectors
}}
+

Revision as of 03:17, 25 October 2011



Introduction

The Ant Jetty plugin is in the codehouse trunk in the jetty-ant 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 a tight integration with the build system.

Preparation

You will need a jetty distribution and the jetty-ant jar in order to set up your project for ant to run jetty:

  1. Get a jetty distribution and unpack it the local filesystem
  2. Get the jetty-ant jar
  3. Make a directory in your project called jetty-lib/
  4. Copy all of the jars in your jetty distribution's lib directory, and all its subdirectories, into your new jetty-lib dir. When copying the jars, DON'T preserve the jetty distro's lib dir hierarchy - all the jars should be directly inside your jetty-lib dir.
  5. Also copy the jetty-ant jar you downloaded earlier into the jetty-lib dir.
  6. Make a directory in your project called jetty-temp

Now you're ready to edit or create your Ant build.xml file.

Preparing the build.xml file

Let's start with an empty build.xml:

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

Then, you must define a jetty task:

<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 you 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>

This is the minimal configuration need. You can now start jetty.

Starting Jetty via Ant

At the command line do:

ant jetty.run

Deploying web applications

To add web applications to the Jetty web server, now put 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>

You can put many webapp tags inside jetty tag, thus deploying many web applications simultaneously.

A Special Note on Using JSPs with JSTL Or Other Taglibs

If your webapp uses a taglib that should be found on the container classpath (such as JSTL) you will need to pass in some extra information to the webapp to tell jetty which container jars can contain the taglibs. This is defined as a set of jar name patterns.

If you are using JSTL, and are using the jars provided by the standard jetty distribution, the JSTL taglibs are located in the jar named something like org.apache.taglibs.standard.glassfish_1.2.0.xxxx.jar (where xxx is replaced by a specific version number).

The following pattern defines all jars that contain the string "jsp-api" or "jsp" or "taglibs" as jars that will be searched at runtime for taglibs:

.*/.*jsp-api-[^/]*\.jar$|.*/.*jsp-[^/]*\.jar$|.*/.*taglibs[^/]*\.jar$


This pattern should be added to your <webApp/> declaration as the value of a context attribute named org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern. Here's how the modified build.xml file looks now:

 
<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">
        <attributes>
          <attribute name="org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern" value=".*/.*jsp-api-[^/]*\.jar$|.*/.*jsp-[^/]*\.jar$|.*/.*taglibs[^/]*\.jar$"/>
        </attributes>
      </webApp>
    </jetty>
  </target>
</project>

Plugin syntax

There are many ways to configure jetty tasks:

  • tempDirectory–specifies the Jetty temporary web directory:
 <jetty tempDirectory="jetty-temp" />
  • requestLog–defines a request logger:
 
 <jetty ... requestLog="your.fancy.request.logger"/>
  • jettyXml–applies additional configuration via a standard jetty.xml file:
 
 <jetty ... jettyXml="path/to/jetty.xml"/>
  • systemProperties–adds system properties when starting Jetty:
 
 <jetty ...>
   <systemProperties>
     <systemProperty name="jetty.status" value="Jetty Rocks!"/>
   </systemProperties>
 </jetty>
  • connectors–defines Jetty connectors:
 
 <typedef name="selectChannelConnector" classname="org.eclipse.jetty.nio.SelectChannelConnector"
                            classpathref="jetty.plugin.classpath" loaderref="jetty.loader" />
 ...
 <jetty ...>
   <connectors>
     <selectChannelConnector port="8090" />
   </connectors>
 </jetty>
  • loginServices - adds authentication via user "realms":
> 
 <typedef name="hashLoginService" classname="org.eclipse.jetty.security.HashLoginService"
                  classpathref="jetty.plugin.classpath" loaderref="jetty.loader" />
 ...
 <jetty ...>
   <loginServices>
     <hashLoginService name="realm1" config="path/to/realm/config" />
   </loginServices>
 </jetty>

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:
 
 <jetty ...>
   <webapp name="name" .../>
 </jetty>
  • warfile–path to .war file or a directory with web application contents:
 
 <jetty ...>
   <webapp warfile="/path/to/war/file/or/web/application/contents" .../>
 </jetty>
  • 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):
 
 <jetty ...>
   <webapp contextPath="/webapp" .../>
 </jetty>
 
 <jetty ...>
   <webapp jettyEnvXml="/path/to/jettyEnv.xml" .../>
 </jetty>
  • webXml–path to web.xml file. If not specified, the default (location-of-war-file/WEB-INF/web.xml) location is used:
 
 <jetty ...>
   <webapp webXmlFile="/path/to/web/xml" .../>
 </jetty>
  • scanTargets and scanIntervalSeconds–points to special files/folders that need to be scanned, and specifies scanner interval in seconds. If any of the files changes, the web application is automatically reloaded. You can adjust interval and scanned files per web application.
Note.png
All files included with <classes/> or <lib/> tags are automatically scanned for changes if you provide scanIntervalSeconds parameter in the <jetty/> tag. There's no need to add them using the <scanTargets/> section.
 <jetty ...>
   <webapp ... scanIntervalSeconds="5">
     <scanTargets dir="path/to/included/resources">
       <include name="filename/patterns" />
     </scanTargets>
   </webapp>
 </jetty>
  • lib–specifies which libraries need be included for a particular web application (treated as files inside WEB-INF/lib folder). Multiple lib tags are allowed.
 
 <jetty ...>
   <webapp ...>
     <lib dir="path/to/jar/folder" includes="*.jar" excludes="not-needed.jar" />
   </webapp>
 </jetty>
  • classes–specifies which folder contains web application classes (treated as WEB-INF/classes folder). Multiple classes tags are allowed.
 
 <jetty ...>
   <webapp ...>
     <classes dir="path/to/classes/folder" includes="*.class" />
   </webapp>
 </jetty>
  • connectors–specifies additional web application connectors