Jump to: navigation, search

Difference between revisions of "Jetty/Howto/Configure Jetty"

< Jetty‎ | Howto
m
 
(19 intermediate revisions by one other user not shown)
Line 1: Line 1:
 
{{Jetty Howto
 
{{Jetty Howto
| introduction= Configuring Jetty consists of building a network of connectors and handlers and providing their individual configurations. It is a combination of
+
| introduction=  
 +
 
 +
{{Jetty Redirect|http://www.eclipse.org/jetty/documentation/current/configuring.html}}
 +
 
 +
Configuring Jetty consists of building a network of connectors and handlers and providing their individual configurations. It is a combination of
 
* HTTP server configuration (ports, thread pools, buffers, etc.)
 
* HTTP server configuration (ports, thread pools, buffers, etc.)
* Web container configuration (webapps deployment, security realms, JNDI etc.)
+
* Web container configuration (webapps deployment, security realms, JNDI, etc.)
 
* Web application (init parameters, non standard options, etc.)
 
* Web application (init parameters, non standard options, etc.)
See [http://wiki.eclipse.org/Jetty/Reference/Jetty_Architecture Jetty Architecture] for graphical representations of the interactions among connectors and handlers.
+
See [[Jetty/Reference/Jetty_Architecture|Jetty Architecture]] for graphical representations of the interactions among connectors and handlers.
}}
+
 
 
== Configuring Jetty ==
 
== Configuring Jetty ==
Since Jetty components are simply Plain Old Java Objects (POJOs), you can accomplish this assembly and configuration of Jetty by a variety of techniques:
+
Since Jetty components are simply Plain Old Java Objects ([http://en.wikipedia.org/wiki/Plain_Old_Java_Object POJOs]), you can accomplish this assembly and configuration of Jetty by a variety of techniques:
  
[[#IDeveloping Against the Jetty API]]
+
*[[#Developing Against the Jetty API|Developing Against the Jetty API]]
  
[[#Using Jetty XML]]
+
*[[#Using Jetty XML|Using Jetty XML]]
  
[[#Embedding Jetty]]
+
*[[#Embedding Jetty|Embedding Jetty]]
  
[[#Using the Jetty Maven Plugin]]
+
*[[#Using the Jetty Maven Plugin|Using the Jetty Maven Plugin]]
  
[[#Using Your Favorite Dependency Injection Framework: Spring, XBean]]
+
*[[#Using Your Favorite Dependency Injection Framework: Spring, XBean|Using your favorite dependency injection framework: Spring, XBean]]
 
+
[[#Using Jetty WebApp and Context Deployers]]
+
  
 
=== Developing Against the Jetty API ===
 
=== Developing Against the Jetty API ===
Line 42: Line 44:
 
* the handler structure (default handlers and/or a contextHandlerCollections, etc.)
 
* the handler structure (default handlers and/or a contextHandlerCollections, etc.)
 
* the deployment manager that scans for and deploys webapps and contexts
 
* the deployment manager that scans for and deploys webapps and contexts
* login services that provide authentication checking.
+
* login services that provide authentication checking
 
* a request log
 
* a request log
  
Not all Jetty features are configured in <tt>jetty.xml</tt>. There are several optional configuration files that share the same format as <tt>jetty.xml</tt> and, if specified, concatenate to it.  These configuration files are also stored in <tt>$JETTY_HOME/etc/</tt>, and examples of them are in [http://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk/jetty-server/src/main/config/etc/ svn].
+
Not all Jetty features are configured in <tt>jetty.xml</tt>. There are several optional configuration files that share the same format as <tt>jetty.xml</tt> and, if specified, concatenate to it.  These configuration files are also stored in <tt>$JETTY_HOME/etc/</tt>, and examples of them are in [http://dev.eclipse.org/viewsvn/index.cgi/jetty/trunk/jetty-server/src/main/config/etc/?root=RT_JETTY SVN Repository].
  
 
* [[Jetty/Feature/Start.jar|Start.jar]] selects the configuration files to use.   
 
* [[Jetty/Feature/Start.jar|Start.jar]] selects the configuration files to use.   
Line 56: Line 58:
 
* [[Jetty/Reference/webdefault.xml|webdefault.xml]] - Pre-web.xml configuration
 
* [[Jetty/Reference/webdefault.xml|webdefault.xml]] - Pre-web.xml configuration
 
* [[Jetty/Reference/override-web.xml|override-web.xml]] - Post-web.xml configuration
 
* [[Jetty/Reference/override-web.xml|override-web.xml]] - Post-web.xml configuration
 +
 +
<references/>
  
 
=== Embedding Jetty ===
 
=== Embedding Jetty ===
  
As an alternative to bundling your application as a standard WAR to be deployed in Jetty, you can embed Jetty in your application. When you do so, Jetty is a software component that can be instantiated and used in a Java program just like any POJO. For more information and configuration instructions, see [[Jetty/Tutorial/Embedding_Jetty|Embedded Jetty]].
+
You can embed Jetty in an application. This is an alternative to bundling your application as a standard WAR to be deployed in Jetty. Jetty is designed to work as a software component that can be instantiated and used in a Java program just like any any [http://en.wikipedia.org/wiki/Plain_Old_Java_Object POJO]. For more information and configuration instructions, see [[Jetty/Tutorial/Embedding_Jetty|Embedding Jetty]].
  
 
=== Using the Jetty Maven Plugin ===
 
=== Using the Jetty Maven Plugin ===
Line 69: Line 73:
  
 
=== Using Your Favorite Dependency Injection Framework: Spring, XBean ===
 
=== Using Your Favorite Dependency Injection Framework: Spring, XBean ===
 +
You can use almost any IoC-style framework, including Spring and XBean, to assemble and configure Jetty.
  
 
==== Configuring Jetty with [http://www.springsource.org/ Spring] ====
 
==== Configuring Jetty with [http://www.springsource.org/ Spring] ====
[[Jetty/Tutorial/Embedding_Jetty#File_Server_with_spring|Spring XML]]
+
The jetty-spring module is included in jetty@codehaus with some convenience classes and a Main method to run Jetty from Spring. For more information, see:
 +
 
 +
* [[Jetty/Howto/Spring|How to Configure Jetty Using Spring]]
 +
* [[Jetty/Tutorial/Embedding_Jetty#File_Server_with_spring|Embedding Jetty with Spring XML]]
  
 
==== Configuring Jetty with [http://geronimo.apache.org/xbean/index.html XBean] ====
 
==== Configuring Jetty with [http://geronimo.apache.org/xbean/index.html XBean] ====
 +
Jetty7 includes support for XBean, allowing you to use an XML format to customize Jetty within an XBean configuration file. For more information, see [[Jetty/Howto/Configure_Jetty_with_XBean|Configuring Jetty with XBean]].
  
=== Using Jetty WebApp and Context Deployers ===
+
== Consulting the Jetty API Docs ==
[http://wiki.eclipse.org/Jetty/Howto/Deploy_Web_Applications WebApp and Context Deployers]
+
  
== More ==
+
The [http://download.eclipse.org/jetty/stable-7/apidocs/ Jetty API docs] are the ultimate resource for configuration, regardless of  the configuration method you use. This is because Jetty configuration can be considered as calling setters on a collection of POJOs.
For more configuration references, see the [[Jetty/Reference#Configuration|Jetty Configuration Reference]] pages. For
+
}}
 
+
== Finally ==
+
Because Jetty configuration can be considered as calling setters on a collection of POJOs, regardless of the actual method used, the [http://download.eclipse.org/jetty/stable-7/apidocs/ apidocs] are the ultimate resource for configuration.
+
 
+
=== References ===
+
<references/>
+

Latest revision as of 12:56, 23 April 2013



Introduction


Configuring Jetty consists of building a network of connectors and handlers and providing their individual configurations. It is a combination of

  • HTTP server configuration (ports, thread pools, buffers, etc.)
  • Web container configuration (webapps deployment, security realms, JNDI, etc.)
  • Web application (init parameters, non standard options, etc.)

See Jetty Architecture for graphical representations of the interactions among connectors and handlers.

Configuring Jetty

Since Jetty components are simply Plain Old Java Objects (POJOs), you can accomplish this assembly and configuration of Jetty by a variety of techniques:

Developing Against the Jetty API

You can develop both standard web applications and embedded web applications by writing code. The basic approach is to install the required Jetty-7 jars and dependencies on your class path and then write and run a variation of one of the examples in the Embedding Jetty Tutorial.

For more details about setting up your class path, see:

For more information on developing against the Jetty API, as well as explanations of other tools, including the Jetty Maven, Ant, and OSGi plugins, see: How to Develop Jetty.

Above all, study the examples in the Jetty 7 Latest Source XRef.

Using Jetty XML

Jetty XML offers XML equivalents to code. It is based on Java's Reflection API. Classes in the java.lang.reflect represent Java methods and classes, such that you can instantiate objects and invoke their methods based on their names and argument types. Behind the scenes, Jetty's XML config parser translates the XML elements and attributes into Reflection calls.[1]

The default configuration file for Jetty is jetty.xml, typically located at $JETTY_HOME/etc/jetty.xml. Usually jetty.xml configures these components:

  • the Server class (or subclass if extended) and global options
  • a ThreadPool (min & max thread)
  • connectors (ports, timeouts, buffer sizes, protocol, etc.)
  • the handler structure (default handlers and/or a contextHandlerCollections, etc.)
  • the deployment manager that scans for and deploys webapps and contexts
  • login services that provide authentication checking
  • a request log

Not all Jetty features are configured in jetty.xml. There are several optional configuration files that share the same format as jetty.xml and, if specified, concatenate to it. These configuration files are also stored in $JETTY_HOME/etc/, and examples of them are in SVN Repository.

Additional Resources

  1. Ethan McAllum makes this point in his appreciative article about Jetty, What is Jetty

Embedding Jetty

You can embed Jetty in an application. This is an alternative to bundling your application as a standard WAR to be deployed in Jetty. Jetty is designed to work as a software component that can be instantiated and used in a Java program just like any any POJO. For more information and configuration instructions, see Embedding Jetty.

Using the Jetty Maven Plugin

Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project's build, reporting and documentation from a central piece of information. It is an ideal tool to build a web application project, and such projects can use the Jetty Maven Plugin to run the web application in development mode. For information and configuration instructions, see

Using Your Favorite Dependency Injection Framework: Spring, XBean

You can use almost any IoC-style framework, including Spring and XBean, to assemble and configure Jetty.

Configuring Jetty with Spring

The jetty-spring module is included in jetty@codehaus with some convenience classes and a Main method to run Jetty from Spring. For more information, see:

Configuring Jetty with XBean

Jetty7 includes support for XBean, allowing you to use an XML format to customize Jetty within an XBean configuration file. For more information, see Configuring Jetty with XBean.

Consulting the Jetty API Docs

The Jetty API docs are the ultimate resource for configuration, regardless of the configuration method you use. This is because Jetty configuration can be considered as calling setters on a collection of POJOs.