Skip to main content
Jump to: navigation, search

Jetty/Reference/jetty.xml usage


Jetty provides an XML-based configuration. 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.

Using jetty.xml

To use jetty.xml, specify it as a configuration file when running Jetty.

java -jar start.jar etc/jetty.xml
Configuration files
If you start up Jetty without specifying a configuration file, Jetty will automatically locate and use the default installation jetty.xml file. Therefore java -jar start.jar is equivalent to java -jar start.jar etc/jetty.xml.

Multiple Configuration Files

You are not limited to one configuration file; you may use multiple configuration files when running Jetty, and Jetty will configure the appropriate server instance.

The id of the server in the <Configure> tag specifies which instance you wish to configure. Each server id in a configuration file creates a new Server instance within the same JVM. If the same id is used across multiple configuration files, those configurations are all applied to the same server.

Parameterizing Configuration Files

The configuration files may be parameterized with either system properties (using <SystemProperty>) or properties files (using <Property>) passed via the command line. For example, this code in jetty.xml allows the port to be defined on the command line, falling back onto 8080 if the port was not specified:

  <Set name="port"><SystemProperty name="jetty.port" default="8080"/></Set>

Then you modify the port while running Jetty by using this command:

java -Djetty.port=8888 -jar start.jar etc/jetty.xml

An example of defining both system properties and properties files from the command line:

java -Djetty.port=8888 -jar start.jar etc/jetty.xml etc/other.xml

Back to the top