title: Embedded Jetty: How do I call setSessionTrackingModes without a ServletContextListener
body: <p>I'm wiring up an embedded Jetty server in my <code>main</code> and I want to enforce only cookies as a session tracking mode. </p>
  
  <p>So I try to do:</p>
  
  <pre><code>//in main
  ServletContextHandler contextHandler = 
      new ServletContextHandler(ServletContextHandler.SESSIONS);
  
  contextHandler
      .getServletContext()
      .setSessionTrackingModes(EnumSet.of(SessionTrackingMode.COOKIE));
  </code></pre>
  
  <p>But I get the following:</p>
  
  <pre><code>Exception in thread "main" java.lang.IllegalStateException
  at org.eclipse.jetty.servlet.ServletContextHandler$Context.setSessionTrackingModes(ServletContextHandler.java:1394)
  </code></pre>
  
  <p>My servlet context is not yet initialized.</p>
  
  <p>The obvious solution is to do this in a <code>ServletContextListener</code>, but I'd rather not. I want all wiring and setup to stay in one central place without using Listeners. </p>
  
  <p>Is there a way?</p>