How do I configure Jetty?
A Jetty is configured by dependency injection into the Jetty components. The root component of Jetty is Server, on which you can set an array of Connector instances and an array of Handler instances. Each specific type of connector and handler will have it's own setters and getters for configuration.
A Typical Configuration
- The JVM will have a single instance of Server
Serverwill have a single
Connectorinstance, probably a SelectChannelConnector.
Connectorwill have a port set on it.
Serverwill have one or more handlers. Typically these will be instances of ContextHandler that wrap other Handler instances for a given context path.
ContextHandlerwill be configured with a contextPath and wrapped handler for the context.
ContextHandlermay be configured with ResourceBase, ClassLoader, VirtualHosts, etc.
ContextHandlermay be an instance of WebAppContext which configures itself from the
WEB-INF/web.xml file found within the configured ResourceBase and will contain a SessionHandler, which will contain a SecurityHandler, which will container a ServletHandler
ContextHandlermay contain a
ServletHandler, which will contain:
All these components have setters and getters for configuration. These may be configured by:
- Directly calling the API in a java program
- Calling the API via Jetty XML
- Calling the bean style API via a framework such as swing or xbeans
All container setup, such as ports to listen on, webapps to deploy, thread pools, security etc is done in a jetty configuration file in xml format. An example of such a file is provided in the distribution as etc/jetty.xml. For more information on this file, see the FAQ entry jetty.xml
Additional configuration can be performed on a per webapp basis in a file called jetty-web.xml file placed inside the WEB-INF directory of the webapp. See also jetty-web.xml