javajettyjetty-12

Jetty 12 throwing exception on new Server()


I have a project running some tests with the jetty 12 server (why is is called legace server btw?).

        <!-- https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-server -->
    <dependency>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-server</artifactId>
        <version>12.0.8</version>
    </dependency>

I have this init method to create a server:

 protected static void initServer() throws Exception {
    freeHttpPort = PortUtility.getFreePort();
    freeHttpsPort = PortUtility.getFreePort(freeHttpPort);
    server = new Server();
    server.setStopAtShutdown(true);

    // create a http connector
    final ServerConnector httpConnector = new ServerConnector(server, 1, 1, new HttpConnectionFactory());
    httpConnector.setPort(freeHttpPort);
    server.addConnector(httpConnector);


    // create two way ssl factory
    final SslContextFactory sslContextFactory = new SslContextFactory.Server();
    final KeyStore keyStore = load("/server.p12", "xxx");
    sslContextFactory.setKeyStorePassword("xxx");
    sslContextFactory.setKeyStore(keyStore);
    sslContextFactory.setTrustStorePassword("xxx");
    sslContextFactory.setTrustStore(keyStore);

    HttpConfiguration secureConfig = new HttpConfiguration();
    secureConfig.addCustomizer(new SecureRequestCustomizer());
    HttpConnectionFactory https = new HttpConnectionFactory(secureConfig);
    ConnectionFactory ssl = new SslConnectionFactory((SslContextFactory.Server) sslContextFactory, https.getProtocol());
    ServerConnector secureConnector = new ServerConnector(server, 1, 1, ssl, https);
    server.addConnector(secureConnector);

}

When the test runs, it starts the server,but I get the following exception at new Server();:

java.lang.NoSuchMethodError: 'boolean org.eclipse.jetty.server.Handler$Wrapper.installBean(java.lang.Object)'

How to solve this? Am I missing a dependency? I found it hard to see what dependencies I needed for a basic jetty 12 server. I tried to follow the programming guide: https://eclipse.dev/jetty/documentation/jetty-12/programming-guide/index.html#pg-server


Solution

  • You have a mix of Jetty versions in your dependency tree.

    Run mvn dependency:tree and look at your jetty versions.

    Fix the mismatched jetty versions and you should have success.

    If you use Maven, consider using the maven bom for jetty core (note there are ee# specific ones too)

    <dependencyManagement>
      <dependencies>
        <dependency>
          <groupId>org.eclipse.jetty</groupId>
          <artifactId>jetty-bom</artifactId>
          <version>12.0.8</version>
          <type>pom</type>
          <scope>import</scope>
        </dependency>