title: Jetty: Pass object from main method to servlet
body: <p>I have two classes <code>Server</code> (with the main method, starting the server) and <code>StartPageServlet</code> with a Servlet.</p>
  
  <p>The most important part of the code is:</p>
  
  <pre><code>public class Server {
      public static void main(String[] args) throws Exception {
          // some code
  
          // I want to pass "anObject" to every Servlet.
          Object anObject = new Object();
  
          Server server = new Server(4000);
          ServletContextHandler context = 
              new ServletContextHandler(ServletContextHandler.SESSIONS);
          context.addServlet(StartPageServlet.class, "/");
          // more code
  }
  </code></pre>
  
  <p>And the StartPageServlet:</p>
  
  <pre><code>public class StartPageServlet extends HttpServlet {
  
      @Override
      public void doGet(HttpServletRequest request,
                        HttpServletResponse response)
              throws ServletException, IOException
      {
          // Here I want to access "anObject"
      }
  </code></pre>
  
  <p>How do I do this?</p>