//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//

[[jetty-xml-usage]]
=== Jetty XML Usage

Jetty provides an XML-based configuration.
It is grounded in 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-jettyxml]]
==== Using jetty.xml

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

[source, java, subs="{sub-order}"]
----
 java -jar start.jar etc/jetty.xml
----

____
[NOTE]
If you start Jetty without specifying a configuration file, Jetty automatically locates and uses the default installation `jetty.xml` file.
Therefore `java -jar start.jar` is equivalent to `java -jar start.jar etc/jetty.xml` .
____

[[using-multiple-configuration-files]]
==== Using Multiple Configuration Files

You are not limited to one configuration file; you can 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 the instance you want to configure.
Each server ID in a configuration file creates a new server instance within the same JVM.
If you use the same ID across multiple configuration files, those configurations are all applied to the same server.

[[setting-parameters-in-configuration-files]]
==== Setting Parameters in Configuration Files

You can set parameters in configuration files either with 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 is not specified:

[source, xml, subs="{sub-order}"]
----
  <Set name="port"><SystemProperty name="jetty.http.port" default="8080"/></Set>
----

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

[source, java, subs="{sub-order}"]
----
 java -Djetty.http.port=8888 -jar start.jar etc/jetty.xml
----

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

[source, java, subs="{sub-order}"]
----
 java -Djetty.http.port=8888 -jar start.jar myjetty.properties etc/jetty.xml etc/other.xml
----
