title: Configure embedded jetty with web.xml?
body: <p>I am trying to generate both a war with my web application as well as a self contained jar file with embedded jetty. For the embedded jetty (the jar file distribution) I add a servlet as follows:</p>
  
  <pre><code>public static void main(String[] args) throws Exception {
      Server server = new Server(8080);
  
      ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
      context.setContextPath("/");
      server.setHandler(context);
  
      context.addServlet(new ServletHolder(new HelloServlet()),"/*");
  
      server.start();
      server.join();
  }
  </code></pre>
  
  <p>The war file distribution uses a web.xml file that contains the following in the web-app section:</p>
  
  <pre><code>&lt;servlet&gt;
      &lt;servlet-class&gt;com.example.HelloServlet&lt;/servlet-class&gt;
      &lt;servlet-name&gt;SimplestServer&lt;/servlet-name&gt;
  &lt;/servlet&gt;
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;HelloServlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p>This works. However, I want to get rid of the duplication between the two approaches. I.e., when I add a new servlet I want to have to configure it in only one location. Can I load and use the web.xml file from the embedded jetty?</p>