org.eclipse.jetty.util.ssl.SslContextFactory$Client ClassNotFoundException upgrading to Jetty Server 9.4.16
Asked Answered
H

1

6

I have a working application that's been using jetty-server version 9.4.15.v20190215. Due to a vulnerability scan that found issues in jetty-server dependencies, I looked into upgrading my app to use jetty-server 9.4.19-v20190610, the latest release as I'm writing this.

I tried to compile the application again, and I'm getting this error during startup:

Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/jetty/util/ssl/SslContextFactory$Client
    at org.eclipse.jetty.websocket.client.HttpClientProvider.get(HttpClientProvider.java:49)
    at org.eclipse.jetty.websocket.client.WebSocketClient.<init>(WebSocketClient.java:261)
    at org.eclipse.jetty.websocket.jsr356.ClientContainer.<init>(ClientContainer.java:140)
    at org.eclipse.jetty.websocket.jsr356.server.ServerContainer.<init>(ServerContainer.java:94)
    at org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer.configureContext(WebSocketServerContainerInitializer.java:152)
    at it.kahoot.merlin.jetty.JettyServer.main(JettyServer.java:53)
Caused by: java.lang.ClassNotFoundException: org.eclipse.jetty.util.ssl.SslContextFactory$Client
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 6 more

I understand the class org.eclipse.jetty.util.ssl.SslContextFactory$Client is not found anymore.

How do I proceed?

Hersch answered 8/8, 2019 at 13:43 Comment(1)
I encountered up with a similar one during migrating from spring boot V.2 to V.3 in embedded Jetty V.9.4.56.v20240826 in server module in factory which expects a SslContextFactory AAP.Rayford
H
11

By tracing back the jetty-server versions to the first one that causes this issue, I found that it's jetty-server version 9.4.16.v20190411, whose release notes mention the following:

jetty-9.4.16.v20190411 - 11 April 2019
 ...
 + 3464 Split SslContextFactory into Client and Server
 ...

Given the class name, I figured I needed to add jetty-util to my dependencies (pom.xml), so I did:

<!-- pom.xml -->
...
<properties>
  <jetty.version>9.4.19.v20190610</jetty.version>
</properties>

<dependency>
  <groupId>org.eclipse.jetty</groupId>
  <artifactId>jetty-server</artifactId>
  <version>${jetty.version}</version>
</dependency>

<!-- Needed for the SSLContextFactory$Client class -->
<dependency>
  <groupId>org.eclipse.jetty</groupId>
  <artifactId>jetty-util</artifactId>
  <version>${jetty.version}</version>
</dependency>

Compilation and startup now work again with the newest Jetty.

Hersch answered 8/8, 2019 at 13:43 Comment(2)
The issue #3464 did introduce new SslContextFactory.Client and SslContextFactory.Server classes, but didn't mandate it. Somehow, your dependency on jetty-server didn't pull in the correct version of jetty-util. That's suspicious, as it likely means you have some other dependency that needs an older version jetty-util. Forcing a newer jetty-util like you are doing could be breaking this other dependency.Calpac
Thanks @JoakimErdfelt. Looking at the maven dependency tree, it seems that the jetty-server dependency is only pulling jetty-http and jetty-io (of the same versions).Hersch

© 2022 - 2024 — McMap. All rights reserved.