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

标签 java android websocket embedded-jetty cometd

我正在尝试为 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$1.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 可用)

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

关于java - 尝试创建新的 Jetty WebSocketClient 实例时抛出 ServiceConfigurationError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46296514/

相关文章:

java 将jpg保存为png

java - 带有 Spring Boot 和多个模式的 Liquibase,如何指定执行顺序

java - 从数据库android填充微调器

ruby - 调试 websocket 1006

java - Hibernate 5.2.10 DDL 自动更新到 AWS RDS (MySql 5.6.10a) 创建 TINYBLOB for Instant

java - Squeryl 子句(from、select、like、where)在 intellij 中不起作用

java - GC 会在 Android 上自动处理/释放在 jni 中分配的内存吗?

android - 如何使 Spinner 可编辑?

actionscript-3 - 是否可以将 flash 套接字和 websockets 与套接字 io 同时使用?

Java : Opening client socket