{title:'Jetty.xml file', created:'8.0.0', deprecated:'8.1.2'}

The Jetty microservice comes with a bare-bones jetty.xml file which can be modified to suite any needs.

The jetty.xml can be located in either the "." or "files" working directory or classpath. It can also be specified in any of the following ways:

- Using the {@link oaj.microservice.jetty.JettyMicroservice.Builder#jettyXml(Object,boolean)} method to specify the location or contents of the file.
- Specifying the location using a Jetty-Config value in the MANIFEST.MF file.

  | Jetty-Config: files/jetty.xml

- Specifying the location using the "Jetty/jettyXml" configuration value.

  | #======================================================================================================================= | # Jetty settings | #======================================================================================================================= | [Jetty] | | # Path of the jetty.xml file used to configure the Jetty server. | config = files/jetty.xml

SVL variables in the jetty.xml file are automatically resolved by the microservice. This allows you to reference values in your configuration file from the jetty.xml file.

The HTTP port used is controlled via the following:

- The {@link oaj.microservice.jetty.JettyMicroservice.Builder#ports(int...)} method.

  | JettyMicroservice | .create() | .args(args) | .servlets(RootResource.class) | .port(1000,2000,0,0,0) // Try port 1000, then 2000, then 3 random ports. | .build() | .start()

- The "Jetty/ports" configuration property.

  | #======================================================================================================================= | # Jetty settings | #======================================================================================================================= | [Jetty] | | # Port to use for the jetty server. | # You can specify multiple ports. The first available will be used. '0' indicates to try a random port. | port = 1000,2000,0,0,0

The first available port is then made available through the system property "availablePort" so that it can be referenced in our jetty.xml file.

| <Set name="connectors"> | <Array type="org.eclipse.jetty.server.Connector"> | <Item> | <New class="org.eclipse.jetty.server.ServerConnector"> | <Arg> | <Ref refid="ExampleServer" /> | </Arg> | <Set name="port">$S{availablePort,8080}</Set> | </New> | </Item> | </Array> | </Set>

The {@link oaj.microservice.jetty.JettyMicroservice.Builder#jettyServerFactory(JettyServerFactory)} method is also provided to use your own customized Jetty server.