blob: 685395de7e5e86abe732005838c8d8e0e9997abb [file] [log] [blame]
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Chapter&nbsp;3.&nbsp;Jetty Configuration Introduction</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="quick-start.html" title="Part&nbsp;I.&nbsp;Getting Started With Jetty"><link rel="prev" href="quickstart-jetty-coordinates.html" title="Finding Jetty in Maven"><link rel="next" href="quickstart-config-what.html" title="What to Configure in Jetty"><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&nbsp;3.&nbsp;Jetty Configuration Introduction</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="quickstart-jetty-coordinates.html"><i class="icon-chevron-left"></i> Previous</a>&nbsp;</td><th width="60%" align="center">Part&nbsp;I.&nbsp;Getting Started With Jetty<br><a accesskey="p" href="index.html"><i class="icon-home"></i> Home</a></th><td width="20%" align="right">&nbsp;<a accesskey="n" href="quickstart-config-what.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="quick-start-configure"></a>Chapter&nbsp;3.&nbsp;Jetty Configuration Introduction</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="quick-start-configure.html#quickstart-config-how">How to Configure Jetty</a></span></dt><dt><span class="section"><a href="quickstart-config-what.html">What to Configure in Jetty</a></span></dt></dl></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="quickstart-config-how"></a>How to Configure Jetty</h2></div></div></div><div class="toc"><dl><dt><span class="section"><a href="quick-start-configure.html#d0e1371">Jetty POJO Configuration</a></span></dt><dt><span class="section"><a href="quick-start-configure.html#d0e1415">Jetty Start Configuration Files</a></span></dt><dt><span class="section"><a href="quick-start-configure.html#d0e1520">Other Configuration Files</a></span></dt><dt><span class="section"><a href="quick-start-configure.html#d0e1593">Jetty IoC XML format</a></span></dt></dl></div><p>To understand Jetty configuration, you need to understand the "How"
and the "What". This section covers how to configure Jetty in terms of what
mechanisms exist to perform configuration. The <a class="link" href="quickstart-config-what.html" title="What to Configure in Jetty">next section</a> gives an overview of
the action components and fields that you can configure with these
mechanisms.</p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="d0e1371"></a>Jetty POJO Configuration</h3></div></div></div><p>The core components of Jetty are simply Plain Old Java Objects
(<a class="link" href="http://en.wikipedia.org/wiki/Plain_Old_Java_Object" target="_top">POJOs</a>);
the process of configuring Jetty is mostly the process of instantiating,
assembling and setting fields on the Jetty POJOs. You can achieve this
either by:</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p>Writing Java code to directly instantiate and assemble Jetty
objects. This is referred to as <a class="xref" href="embedding-jetty.html" title="Embedding Jetty">Embedding Jetty</a>.</p></li><li class="listitem"><p>Using Jetty XML configuration, which is an <a class="link" href="http://en.wikipedia.org/wiki/Inversion_of_Control" target="_top">Inversion
of Control (IoC)</a> framework, to instantiate and assemble Jetty
objects as XML objects. The <code class="filename">etc/jetty.xml</code> file is
the main Jetty XML configuration file, but there are many other
<code class="filename">etc/jetty-</code><span class="emphasis"><em>feature</em></span><code class="filename">.xml</code>
files included in the jetty distribution.</p></li><li class="listitem"><p>Using a third party <a class="link" href="http://en.wikipedia.org/wiki/Inversion_of_Control" target="_top">
IoC</a> framework like <a class="link" href="http://en.wikipedia.org/wiki/Spring_Framework" target="_top">Spring</a>,
to instantiate and assemble Jetty objects as Spring beans.</p></li></ul></div><p>Because the main Jetty configuration is done by IoC, the <a class="link" href="http://download.eclipse.org/jetty/stable-9/apidocs/" target="_top">Jetty API documentation</a> is the ultimate
configuration reference.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="d0e1415"></a>Jetty Start Configuration Files</h3></div></div></div><p>The Jetty distribution uses the following configuration files to
instantiate, inject and start server via the start.jar mechanism</p><div class="variablelist"><dl><dt><span class="term"><code class="filename">ini files</code></span></dt><dd><p>The Jetty Start mechanism uses the command line, the
<code class="code">$JETTY_BASE/start.ini</code> and/or
<code class="code">$JETTY_BASE/start.d/*.ini</code> files to create an effective
command line of arguments. Arguments may be:</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p>XML files in Jetty IoC (or spring) XML format</p></li><li class="listitem"><p>Module activations in the form --module=name</p></li><li class="listitem"><p>Property in the form of name=value, used to parameterize
Jetty IoC XML</p></li><li class="listitem"><p>A standard <a class="link" href="http://en.wikipedia.org/wiki/Java_properties" target="_top">Java
property file</a> containing additional start
properties</p></li><li class="listitem"><p>Other start.jar options (see java -jar start.jar
--help)</p></li><li class="listitem"><p>Some JVM options</p></li></ul></div><p>It is the ini files are located in the jetty base (if
different from jetty home) that are typically edited to change the
configuration (Eg change ports)</p></dd><dt><span class="term">mod files</span></dt><dd><p>The <code class="code">$JETTY_HOME/modules/*.mod</code> files contain the
definition of modules that can be activated by --module=name. Each
mod file defines:</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p>Module dependencies for ordering and activation</p></li><li class="listitem"><p>The libraries needed by the module to be added to the
classpath</p></li><li class="listitem"><p>The XML files needed by the module to be added to the
effective command line</p></li><li class="listitem"><p>Files needed by the activated module</p></li><li class="listitem"><p>A template ini file to be used when activating with the
--add-to-start=name option</p></li></ul></div><p>Typically module files are rarely edited and only for
significant structural changes. The *.mod files are normally located
<code class="code">$JETTY_HOME/modules/</code>, but extra or edited modules may
be added to <code class="code">$JETTY_BASE/module</code>. If module changes are
required, it is best practise to copy the particular *.mod file from
<code class="code">$JETTY_HOME/modules/</code> to
<code class="code">$JETTY_BASE/modules/</code> before being modified.</p></dd><dt><span class="term">XML files</span></dt><dd><p>XML files in <a class="link" href="reference-section.html#jetty-xml-syntax" title="Jetty XML Syntax">Jetty IoC XML
format</a> or spring IoC format are listed either on the command
line, in ini files or are added to the effective command line by a
module definition. The XML files instantiate and inject the actual
Java objects that comprise the server, connectors and contexts.
Because Jetty IoC XML files use properties, most common
configuration tasks can be accomplished without editing these XML
files and can instead be achieved by editing the properti in the
corresponding ini files.</p><p>The XML files are normally located
<code class="code">$JETTY_HOME/etc/</code>, but extra or edited XML files may be
added to <code class="code">$JETTY_BASE/etc/</code>. If XML configuration changes
are required, it is best practise to copy the XML file from
<code class="code">$JETTY_HOME/etc/</code> to <code class="code">$JETTY_BASE/etc/</code>
before being modified.</p></dd></dl></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="d0e1520"></a>Other Configuration Files</h3></div></div></div><p>In addition to the start configuration files described above, the
configuration of the server can use the following file:</p><div class="variablelist"><dl><dt><span class="term">Context XML files</span></dt><dd><p>Any XML files in <a class="link" href="reference-section.html#jetty-xml-syntax" title="Jetty XML Syntax">Jetty IoC
XML format</a> or spring IoC format that is discovered in the
webapps directory are used by the deploy module to instantiate and
inject HttpContext instances to create a specific context. These may
be standard web applications or bespoke contexts created from
special purpose handlers.</p></dd><dt><span class="term"><code class="filename">web.xml</code></span></dt><dd><p>The <a class="link" href="http://en.wikipedia.org/wiki/Servlet" target="_top">Servlet</a>
Specification defines the <a class="link" href="http://en.wikipedia.org/wiki/Web.xml" target="_top">
<code class="filename">web.xml</code> </a> deployment descriptor that
defines and configures the filters, servlets and resources a <a class="link" href="http://en.wikipedia.org/wiki/Web_application" target="_top">web
application</a> uses. The Jetty WebAppContext component uses this
XML format to:</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p>Set up the default configuration of a web application
context.</p></li><li class="listitem"><p>Interpret the application-specific configuration supplied
with a web application in the <code class="filename">
WEB-INF/web.xml</code> file.</p></li><li class="listitem"><p>Interpret descriptor fragments included in the
<code class="filename">META-INF</code> directory of Jar files within
<code class="filename">WEB-INF/lib.</code></p></li></ul></div><p>Normally the web.xml file for a web application is found in
the WEB-INF/web.xml location within the war file/directory or as
web.xml fragments with jar files found in WEB-INF/lib. Jetty also
supports multiple web.xml files so that a default descriptor may be
applied before WEB-INF/web.xml (typically set to etc/webdefault.xml
by the deploy module) and an override descriptor may be applied
after WEB-INF/web.xml (typically set by a context XML file see
test.xml)</p></dd><dt><span class="term">Property Files</span></dt><dd><p>Standard <a class="link" href="http://en.wikipedia.org/wiki/Java_properties" target="_top">Java property
files</a> are also used for Jetty configuration in several
ways:</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p>To parameterize Jetty IoC XML via the use of the Property
element.</p></li><li class="listitem"><p>To configure the default logging mechanism (StdErrLog).
You can also plug in other logging frameworks, and also use
property files (for example, log4j).</p></li><li class="listitem"><p>As a simple database for login usernames and
credentials.</p></li></ul></div></dd></dl></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="d0e1593"></a>Jetty IoC XML format</h3></div></div></div><p>To understand the <a class="link" href="reference-section.html#jetty-xml-syntax" title="Jetty XML Syntax">Jetty IoC XML
format</a>, consider the following example of an embedded Jetty server
instantiated and configured in java:</p><script type="syntaxhighlighter" class="brush: java;toolbar: false">
<![CDATA[package org.eclipse.jetty.embedded;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.servlet.ServletContextHandler;
public class ExampleServer {
public static void main(String[] args) throws Exception {
Server server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setPort(8080);
server.setConnectors(new Connector[] { connector });
ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/");
context.addServlet(HelloServlet.class, "/hello");
context.addServlet(AsyncEchoServlet.class, "/echo/*");
HandlerCollection handlers = new HandlerCollection();
handlers.setHandlers(new Handler[] { context, new DefaultHandler() });
server.setHandler(handlers);
server.start();
server.join();
}
}
]]>
</script><p><a class="link" href="reference-section.html#jetty-xml-syntax" title="Jetty XML Syntax">Jetty IoC XML format</a> allows
you to instantiate and configure the exact same server in XML without
writing any java code:</p><script type="syntaxhighlighter" class="brush: xml;toolbar: false">
<![CDATA[<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure id="ExampleServer" class="org.eclipse.jetty.server.Server">
<Set name="connectors">
<Array type="org.eclipse.jetty.server.Connector">
<Item>
<New class="org.eclipse.jetty.server.ServerConnector">
<Arg><Ref refid="ExampleServer"/></Arg>
<Set name="port">8080</Set>
</New>
</Item>
</Array>
</Set>
<New id="context" class="org.eclipse.jetty.servlet.ServletContextHandler">
<Set name="contextPath">/hello</Set>
<Call name="addServlet">
<Arg>org.eclipse.jetty.embedded.HelloServlet</Arg>
<Arg>/</Arg>
</Call>
</New>
<Set name="handler">
<New class="org.eclipse.jetty.server.handler.HandlerCollection">
<Set name="handlers">
<Array type="org.eclipse.jetty.server.Handler">
<Item>
<Ref refid="context" />
</Item>
<Item>
<New class="org.eclipse.jetty.server.handler.DefaultHandler" />
</Item>
</Array>
</Set>
</New>
</Set>
</Configure>
]]>
</script><p>In practise, most commonly used Jetty features have XML files that
are included in the standard distribution in the <code class="filename">etc</code>
directory. Thus configuring Jetty is often a matter of just editing
existing XML files and altering the property values injected into
them.</p></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="quickstart-jetty-coordinates.html"><i class="icon-chevron-left"></i> Previous</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="quick-start.html"><i class="icon-chevron-up"></i> Top</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="quickstart-config-what.html">Next <i class="icon-chevron-right"></i></a></td></tr><tr><td width="40%" align="left" valign="top">Finding Jetty in Maven&nbsp;</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">&nbsp;What to Configure in Jetty</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:14-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>