Integrating Jetty 9.4 Adapter with a standalone Jetty server app

I am integrating a Jetty standalone server application with Keycloak. I haven’t been able to find any documentation on how to do this, and when I try integrating by passing a KeyCloakJettyAuthenticator instance to setAuthenticator I get a NPE.

This is my integration code so far.

public class ExampleApplication
{

    private static final int SERVER_PORT = 8090;

    public static Server createServer(int port) throws URISyntaxException {
        Server server = new Server(port);

        ServletContextHandler servletContextHandler = new ServletContextHandler(
                ServletContextHandler.NO_SESSIONS
        );
        servletContextHandler.setContextPath("/");
        server.setHandler(servletContextHandler);

        KeycloakJettyAuthenticator keycloakJettyAuthenticator = new KeycloakJettyAuthenticator();

        SecurityHandler securityHandler = servletContextHandler.getSecurityHandler();
        securityHandler.setAuthenticator(keycloakJettyAuthenticator);

        ServletHolder servletHolder = servletContextHandler.addServlet(
                ServletContainer.class,
                "/api/*"
        );
        servletHolder.setInitParameter(
                "com.sun.jersey.config.property.packages",
                "org.example.resources"
        );

        URL keycloakConfigUrl = ExampleApplication.class.getClassLoader().getResource("keycloak.json");
        File keycloakConfigFile = new File(keycloakConfigUrl.toURI());
        servletContextHandler.setInitParameter(
                "keycloak.config.file",
                keycloakConfigFile.toString()
        );

        return server;
    }

    public static void main(String[] args) throws Exception
    {
        Server server = createServer(SERVER_PORT);

        try {
            server.start();
            server.join();
        } catch (Exception ex) {
            System.exit(1);
        }

        finally {
            server.destroy();
        }
    }
}

I get a NPE on the following line

securityHandler.setAuthenticator(keycloakJettyAuthenticator);

FYI I was able to successfully integrate with the servlet filter adapter. What is the difference between the servlet filter adapter and jetty adapters?