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

时间:2017-09-19 09:19:18

标签: java android websocket embedded-jetty cometd

我正在尝试为cometD创建一个没有args构造函数的新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]]

1 个答案:

答案 0 :(得分:1)

正如评论中提到的sbordet,问题在于缺少依赖性。将此添加到@Inject Config config; @Inject App application; 修复了问题:

build.gradle

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

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