Jetty Logo
Version: 9.2.2-SNAPSHOT
Contact the core Jetty developers at www.webtide.com

private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services from 1 day to full product delivery

Serving a WebApp from a Particular Port/Connector

Creating Multiple Server Instances
Named Connectors

Sometimes it is required to serve different web applications from different ports/connectors. The simplest way to do this is to create multiple Server instances, however if contexts need to share resources (eg data sources, authentication), or if the mapping of ports to web applications is not cleanly divided, then the named connector mechanism can be used.

Creating Multiple Server Instances

How to create multiple server instances is simply done when writing embedded jetty code by creating multiples instances of the Server class and configuring them as needed. This is also easy to achieve if you are configuring your servers in XML. The id field in the Configure element of jetty.xml files is used to identify the instance that the configuration applies to, so to run two instances of the Server, you can copy the jetty.xml, jetty-http.xml and other jetty configuration files used and change the "Server" id to a new name. This can be done in the same style and layout as the existing jetty.xml files or the multiple XML files may be combined to a single file.

When creating new configurations for alternative server:

  • Change all id="Server" to the new server name:<Configure id="OtherServer" class="org.eclipse.jetty.server.Server">

  • For all connectors for the new server change the refid in the server argument: <Arg name="server"><Ref refid="OtherServer" /></Arg>

  • Make sure that any references to properties like jetty.port are either renamed or replaced with absolute values

  • Make sure that any deployers AppProviders refer to a different "webapps" directory so that a different set of applications are deployed.

Example Other Server XML

The following example creates another server instance and configures it with a connector and deployer:

To run the other server, simply add the extra configuration file(s) to the command line:

java -jar start.jar jetty-otherserver.xml

Named Connectors

It is also possible to use an extension to the virtual host mechanism with named to connectors to make some web applications only accessible by specific connectors. If a connector has a name "MyConnector" set using the setName method, then this can be referenced with the special virtual host name "@MyConnector".

See an error or something missing? Contribute to this documentation at Github!(Generated: 2014-08-30T01:00:29-07:00)