Java 尝试创建新Jetty WebSocketClient实例时引发ServiceConfigurationError
我正在尝试创建一个新的Java 尝试创建新Jetty WebSocketClient实例时引发ServiceConfigurationError,java,android,websocket,embedded-jetty,cometd,Java,Android,Websocket,Embedded Jetty,Cometd,我正在尝试创建一个新的WebSocketClient,其中没有cometD的参数构造函数: static BayeuxClient newInstace(String url) throws Exception { WebSocketClient wsClient = new WebSocketClient(); //exception here!! wsClient.start(); Map<String, Object> options = new Has
WebSocketClient
,其中没有cometD的参数构造函数:
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;
}
我把图书馆包括在内如下:
//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'
你知道是什么问题吗?我该如何解决
---------------编辑----------------
这也在stacktrace中:
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)
不知道为什么它不能自动解决。看起来只是一个丢失的罐子。您确定包含
org.eclipse.jetty.websocket.common.extensions.identity.IdentityExtension
的jar在您的Android环境中可用吗?你使用的是什么确切的码头版本?我同意。实际上我不知道。我以为gradle下载了所有必要的依赖项。我使用的maven存储库说Jetty版本是9.2.22.v20170606
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]]
compile group: 'org.eclipse.jetty.websocket', name: 'websocket-common', version: '9.2.22.v20170606'