尝试创建新的 Jetty WebSocketClient 实例时抛出 ServiceConfigurationError

ServiceConfigurationError thrown when trying to create new Jetty WebSocketClient instance

我正在尝试为 cometD 创建一个没有参数构造函数的新 WebSocketClient

static BayeuxClient newInstace(String url) throws Exception {
    WebSocketClient wsClient = new WebSocketClient(); //exception here!!
    wsClient.start();
    Map<String, Object> options = new HashMap<>();
    ClientTransport transport = new JettyWebSocketTransport(options, Executors.newScheduledThreadPool(2), wsClient);
    BayeuxClient client = new BayeuxClient(url, transport);
    return client;
}

但这是抛出运行时异常:

java.util.ServiceConfigurationError: org.eclipse.jetty.websocket.api.extensions.Extension: Provider org.eclipse.jetty.websocket.common.extensions.identity.IdentityExtension not found
    at java.util.ServiceLoader.fail(ServiceLoader.java:225)
    at java.util.ServiceLoader.-wrap1(ServiceLoader.java)
    at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:366)
    at java.util.ServiceLoader.next(ServiceLoader.java:448)
    at org.eclipse.jetty.websocket.api.extensions.ExtensionFactory.<init>(ExtensionFactory.java:35)
    at org.eclipse.jetty.websocket.client.common.extensions.WebSocketExtensionFactory.<init>(WebSocketExtensionFactory.java:36)
    at org.eclipse.jetty.websocket.client.WebSocketClient.<init>(WebSocketClient.java:117)
    at org.eclipse.jetty.websocket.client.WebSocketClient.<init>(WebSocketClient.java:108)
    at org.eclipse.jetty.websocket.client.WebSocketClient.<init>(WebSocketClient.java:88)
    at org.asd.util.customerSupportChat.LekaneClient.newInstace(LekaneClient.java:40)

这发生在 Android

minSdkVersion 21
targetSdkVersion 25

我已经包含了这样的库:

//https://mvnrepository.com/artifact/org.cometd.java/cometd-java-websocket-jetty-client/3.1.2
compile group: 'org.cometd.java', name: 'cometd-java-websocket-jetty-client', version: '3.1.2'

你知道哪里出了问题吗?我该如何解决?

----------------编辑----------------

这也在堆栈跟踪中:

Caused by: java.lang.ClassNotFoundException: Didn't find class "org.eclipse.jetty.websocket.common.extensions.identity.IdentityExtension" on path: DexPathList[[zip file "/data/app/org.asd.debug-2/base.apk"],nativeLibraryDirectories=[/data/app/org.asd.debug-2/lib/x86, /system/lib, /vendor/lib]]

正如 sbordet 在评论中提到的,问题在于缺少依赖项。将此添加到 build.gradle 解决了问题:

compile group: 'org.eclipse.jetty.websocket', name: 'websocket-common', version: '9.2.22.v20170606'

(使用旧版本因为没有 Java 8 个可用)

不知道为什么没有自动解析。