public void run () throws Exception
  {
    if (System.getSecurityManager () != null)
      throw new IllegalStateException ("Security Manager is set but not supported - aborting!");

    final String sTempDir = SystemProperties.getTmpDir ();

    // Create main server
    final Server aServer = new Server (m_aThreadPool);
    {
      // Create connector on Port
      final ServerConnector aConnector = new ServerConnector (aServer);
      aConnector.setPort (m_nPort);
      aConnector.setIdleTimeout (30_000);
      customizeServerConnector (aConnector);
      aServer.setConnectors (new Connector [] { aConnector });
      aServer.setAttribute ("org.eclipse.jetty.server.Request.maxFormContentSize",
                            Integer.valueOf (2 * CGlobal.BYTES_PER_MEGABYTE));
      aServer.setAttribute ("org.eclipse.jetty.server.Request.maxFormKeys", Integer.valueOf (20000));
    }

    customizeServer (aServer);

    final WebAppContext aWebAppCtx = new WebAppContext ();
    {
      aWebAppCtx.setBaseResource (m_aResourceBase);
      aWebAppCtx.setDescriptor (m_sWebXmlResource != null ? m_sWebXmlResource
                                                          : m_aResourceBase.addPath ("/WEB-INF/web.xml").getName ());
      aWebAppCtx.setContextPath (m_sContextPath);
      aWebAppCtx.setTempDirectory (new File (sTempDir + '/' + m_sDirBaseName + ".webapp"));
      aWebAppCtx.setParentLoaderPriority (true);
      aWebAppCtx.setThrowUnavailableOnStartupException (true);
      if (m_sContainerIncludeJarPattern != null)
      {
        // http://www.eclipse.org/jetty/documentation/9.4.x/configuring-webapps.html#container-include-jar-pattern
        // https://github.com/eclipse/jetty.project/issues/680
        aWebAppCtx.setAttribute (WebInfConfiguration.CONTAINER_JAR_PATTERN, m_sContainerIncludeJarPattern);
      }
      if (m_sWebInfIncludeJarPattern != null)
      {
        aWebAppCtx.setAttribute (WebInfConfiguration.WEBINF_JAR_PATTERN, m_sWebInfIncludeJarPattern);
      }

      if (m_bAllowAnnotationBasedConfig)
      {
        // Important to add the AnnotationConfiguration!
        aWebAppCtx.setConfigurations (new Configuration [] { new WebInfConfiguration (),
                                                             new WebXmlConfiguration (),
                                                             new MetaInfConfiguration (),
                                                             new FragmentConfiguration (),
                                                             new AnnotationConfiguration (),
                                                             new JettyWebXmlConfiguration () });
      }
      // else leave default
    }

    // Set session store directory to passivate/activate sessions
    if (m_bSpecialSessionMgr)
    {
      final SessionHandler aHdl = new SessionHandler ();
      final FileSessionDataStore aDataStore = new FileSessionDataStore ();
      aDataStore.setStoreDir (new File (sTempDir + '/' + m_sDirBaseName + ".sessions"));
      aDataStore.setDeleteUnrestorableFiles (true);
      final DefaultSessionCache aCache = new DefaultSessionCache (aHdl);
      aCache.setSessionDataStore (aDataStore);
      aCache.setRemoveUnloadableSessions (true);
      aHdl.setSessionCache (aCache);
      aWebAppCtx.setSessionHandler (aHdl);
    }

    if (StringHelper.hasText (m_sSessionCookieName))
      aWebAppCtx.getSessionHandler ().setSessionCookie (m_sSessionCookieName);

    customizeWebAppCtx (aWebAppCtx);

    aServer.setHandler (aWebAppCtx);
    final ServletContextHandler aCtx = aWebAppCtx;

    // Setting final properties
    // Stops the server when ctrl+c is pressed (registers to
    // Runtime.addShutdownHook)
    aServer.setStopAtShutdown (true);

    if (false)
    {
      // Debug output
      aServer.setDumpBeforeStop (true);
    }

    try
    {
      // Starting shutdown listener thread
      // May fail if port is in use
      if (m_bRunStopMonitor)
        new InternalJettyStopMonitorThread (m_nStopPort, m_sStopKey, () -> aServer.stop ()).start ();

      // Starting the engines:
      aServer.start ();
      LOGGER.info ("Started Jetty" + ":" + m_nPort + ":" + m_nStopPort + " " + m_sAppName);

      // Callback
      onServerStarted (aServer);

      Runtime.getRuntime ().addShutdownHook (new Thread ( () -> {
        try
        {
          aServer.stop ();
          aServer.join ();
        }
        catch (final Exception ex)
        {
          LOGGER.error ("Exception in ShutdownHook of JettyStarter!", ex);
        }
      }));
    }
    catch (final Throwable t)
    {
      // Do not throw something here, in case some exception occurs in finally
      // code
      LOGGER.error ("Failed to start Jetty " + m_sAppName + "!", t);

      // Callback
      onServerStartFailure (aServer, t);
    }
    finally
    {
      if (aCtx.isFailed ())
      {
        LOGGER.error ("Failed to start Jetty " + m_sAppName + " - stopping server!");
        try
        {
          // Throws an Exception e.g. in log4j2 2.5
          aServer.stop ();
          LOGGER.error ("Failed to start Jetty " + m_sAppName + " - stopped server!");
        }
        catch (final Throwable t)
        {
          LOGGER.error ("Error stopping Jetty " + m_sAppName + " after startup errors!", t);
        }
      }
      else
        if (!aServer.isFailed ())
        {
          // Running the server!
          aServer.join ();
        }
    }
  }
public void run ( ) throws Exception { if ( System . getSecurityManager ( ) != null ) throw new IllegalStateException ( "Security Manager is set but not supported - aborting!" ) ; final String sTempDir = SystemProperties . getTmpDir ( ) ; final Server aServer = new Server ( m_aThreadPool ) ; { final ServerConnector aConnector = new ServerConnector ( aServer ) ; aConnector . setPort ( m_nPort ) ; aConnector . setIdleTimeout ( 30_000 ) ; customizeServerConnector ( aConnector ) ; aServer . setConnectors ( new Connector [ ] { aConnector } ) ; aServer . setAttribute ( "org.eclipse.jetty.server.Request.maxFormContentSize" , Integer . valueOf ( 2 * CGlobal . BYTES_PER_MEGABYTE ) ) ; aServer . setAttribute ( "org.eclipse.jetty.server.Request.maxFormKeys" , Integer . valueOf ( 20000 ) ) ; } customizeServer ( aServer ) ; final WebAppContext aWebAppCtx = new WebAppContext ( ) ; { aWebAppCtx . setBaseResource ( m_aResourceBase ) ; aWebAppCtx . setDescriptor ( m_sWebXmlResource != null ? m_sWebXmlResource : m_aResourceBase . addPath ( "/WEB-INF/web.xml" ) . getName ( ) ) ; aWebAppCtx . setContextPath ( m_sContextPath ) ; aWebAppCtx . setTempDirectory ( new File ( sTempDir + '/' + m_sDirBaseName + ".webapp" ) ) ; aWebAppCtx . setParentLoaderPriority ( true ) ; aWebAppCtx . setThrowUnavailableOnStartupException ( true ) ; if ( m_sContainerIncludeJarPattern != null ) { aWebAppCtx . setAttribute ( WebInfConfiguration . CONTAINER_JAR_PATTERN , m_sContainerIncludeJarPattern ) ; } if ( m_sWebInfIncludeJarPattern != null ) { aWebAppCtx . setAttribute ( WebInfConfiguration . WEBINF_JAR_PATTERN , m_sWebInfIncludeJarPattern ) ; } if ( m_bAllowAnnotationBasedConfig ) { aWebAppCtx . setConfigurations ( new Configuration [ ] { new WebInfConfiguration ( ) , new WebXmlConfiguration ( ) , new MetaInfConfiguration ( ) , new FragmentConfiguration ( ) , new AnnotationConfiguration ( ) , new JettyWebXmlConfiguration ( ) } ) ; } } if ( m_bSpecialSessionMgr ) { final SessionHandler aHdl = new SessionHandler ( ) ; final FileSessionDataStore aDataStore = new FileSessionDataStore ( ) ; aDataStore . setStoreDir ( new File ( sTempDir + '/' + m_sDirBaseName + ".sessions" ) ) ; aDataStore . setDeleteUnrestorableFiles ( true ) ; final DefaultSessionCache aCache = new DefaultSessionCache ( aHdl ) ; aCache . setSessionDataStore ( aDataStore ) ; aCache . setRemoveUnloadableSessions ( true ) ; aHdl . setSessionCache ( aCache ) ; aWebAppCtx . setSessionHandler ( aHdl ) ; } if ( StringHelper . hasText ( m_sSessionCookieName ) ) aWebAppCtx . getSessionHandler ( ) . setSessionCookie ( m_sSessionCookieName ) ; customizeWebAppCtx ( aWebAppCtx ) ; aServer . setHandler ( aWebAppCtx ) ; final ServletContextHandler aCtx = aWebAppCtx ; aServer . setStopAtShutdown ( true ) ; if ( false ) { aServer . setDumpBeforeStop ( true ) ; } try { if ( m_bRunStopMonitor ) new InternalJettyStopMonitorThread ( m_nStopPort , m_sStopKey , ( ) -> aServer . stop ( ) ) . start ( ) ; aServer . start ( ) ; LOGGER . info ( "Started Jetty" + ":" + m_nPort + ":" + m_nStopPort + " " + m_sAppName ) ; onServerStarted ( aServer ) ; Runtime . getRuntime ( ) . addShutdownHook ( new Thread ( ( ) -> { try { aServer . stop ( ) ; aServer . join ( ) ; } catch ( final Exception ex ) { LOGGER . error ( "Exception in ShutdownHook of JettyStarter!" , ex ) ; } } ) ) ; } catch ( final Throwable t ) { LOGGER . error ( "Failed to start Jetty " + m_sAppName + "!" , t ) ; onServerStartFailure ( aServer , t ) ; } finally { if ( aCtx . isFailed ( ) ) { LOGGER . error ( "Failed to start Jetty " + m_sAppName + " - stopping server!" ) ; try { aServer . stop ( ) ; LOGGER . error ( "Failed to start Jetty " + m_sAppName + " - stopped server!" ) ; } catch ( final Throwable t ) { LOGGER . error ( "Error stopping Jetty " + m_sAppName + " after startup errors!" , t ) ; } } else if ( ! aServer . isFailed ( ) ) { aServer . join ( ) ; } } }
Run Jetty with the provided settings.

@throws Exception
In case something goes wrong