About Jetty's Xml Configuration Language


Class XmlConfiguration class implements Jetty's configuration language. The distribution file src/org/mortbay/util/configure.dtd contains detailed comments about the structure of Jetty config files. Here is some information in a less-technical form.

The generic Jetty Server creates a org.mortbay.http.HttpServer  object for each config file listed on the command line, configures it according to the configuration script, and then starts it.

Under the <Configure> tag a Jetty config file can have <Call>, <Arg>, <Set>, and <New> tags. The configuration interpreter uses the Java reflection facility to let you call any public method of the current object, to supply arguments to method calls, set properties of the current object, and create new objects.

The <Call> and <New> tags also establish a new "current object" until the matching end tag. You can configure this object with additional XML up to the matching </Call> or </End> tag.

The Jetty configuration language provides a rather general-purpose bridge between the procedural world of Java code and the usually-declarative realm of XML and system configuration. It can easily be used to configure many kinds of objects that provide suitably-structured APIs to initialize and set them up.

Value expressions:

Between their start and end tags, <Arg> and <Set> accept a mixture of text, <Call>, <New>, and <SystemProperty> tags. To determine the value represented, first the interpreter trims away leading and trailing whitespace. If that leaves just a single tag, the interpreter uses the value it computes. If there is text or multiple tags, it converts all of those values to strings as by StringBuffer .append(Object), and treats the result as a String.

If there is nothing between the start and end tags, the value is null except if the type is given as String: in that case the value is the empty String. The optional "type" attribute controls interpretation of the value. Legal types are:

When a type is given, the configuration interpreter tries to interpret the String value as that type using standard, built-in Java methods. Note booleans should be "true" or "false", and are not case-sensitive.

The <Set> Tag

Syntax: <Set name="XXX" type="type">text-and-value-tags</Set>
The <Set> tag converts its input values to primitive types automatically. If the type is not given and the current object has a setXXX method for the object that takes a Java primitive type, the interpreter will try to convert the value to that type.

The Java primitive types are the ones that are not instances of any class: byte, short, int, long, float, double, char, and boolean.


Return to JettyConfiguration