Section 6.3 Implementing jetty.xml
You can programatically create a jetty Server, and still use a jetty.xml file to configure it:
Server server = new Server();
XmlConfiguration configuration = new XmlConfiguration
(new File("myJetty.xml").toURL()); //or use new
XmlConfiguration(new FileInputStream("myJetty.xml"));
configuration.configure(server);
server.start();
Examples:
These examples are all included as part of the standard Jetty distribution in the $JETTY_HOME/examples/embedded sub project.
- FileServer – simple HTTP file server
- OneHandler – Embed a single handler – useful when there is only a single simple source of content.
- Many-Handlers – Embed multiple handlers, one called after the other on each request.
- OneContext – An example of a handler within a context, which allows a contextPath, resourceBase and class loader to be set.
- MinimalServlets – An example of a ServletHandler without a context.
- OneServletContext – A servletHandler within a context, which has been constructed with a session handler.
- ManyServletContexts – Multiple servlet contexts using context path to select the context.
- LikeJettyXml – A code example that mimics the configuration of the standard jetty.xml file.
- FromXmlConfuration – An example that shows how XML fragments may be used to build a server and/or context.


