Java Websocket 客户端找不到实现类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27751630/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Websocket Client Could not find an implementation class
提问by Michael Miner
I will preface this with I am not using any maven dependencies, yet I know that I am missing a jar file wls-api.jar
(at least that is what I have read).
我将以我没有使用任何 maven 依赖项作为序言,但我知道我缺少一个 jar 文件wls-api.jar
(至少这是我读过的)。
To remedy this I downloaded the oracle-weblogic-7.9.jar
but the problem persists.
为了解决这个问题,我下载了 ,oracle-weblogic-7.9.jar
但问题仍然存在。
The exception is thrown at this line
在这一行抛出异常
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
Can anyone tell me why this line continuously fails?
谁能告诉我为什么这条线不断失败?
UPDATE: upon further reading the examples I see use this dependency
更新:进一步阅读示例后,我看到使用此依赖项
<dependency>
<groupId>javax.websocket</groupId>
<artifactId>javax.websocket-api</artifactId>
<version>1.0</version>
I have javax.websocket-api.jar
in the build path of the server and the client as it is required. What am I missing here?
根据需要,我javax.websocket-api.jar
在服务器和客户端的构建路径中。我在这里缺少什么?
Other update: I forgot to include the error thrown!
其他更新:我忘了包括抛出的错误!
Exception in thread "main" java.lang.RuntimeException: Could not find an implementation class.
at javax.websocket.ContainerProvider.getWebSocketContainer(ContainerProvider.java:73)
at connect.<init>(connect.java:21)
at test.main(test.java:11)
采纳答案by Rajendar Reddy
javax.websocket api is only the specification don't have full implementation you may need to take the jar file tyrus-standalone-client-1.9.jar and try the same example that should solve your problem. i tested with my example and it is working fine.
javax.websocket api 只是规范没有完整的实现,您可能需要获取 jar 文件 tyrus-standalone-client-1.9.jar 并尝试应该解决您的问题的相同示例。我用我的例子进行了测试,它工作正常。
hope this will help you.
希望这会帮助你。
回答by James Taylor
I think the RuntimeException
you are experiencing is fortunately not generated by any direct coding fault of your own.
我认为RuntimeException
您所经历的幸运不是由您自己的任何直接编码错误产生的。
The method getWebSocketContainer()
, as described here, simply tries to load other classes and get the static instance of the ContainerProvider
in the server.
的方法getWebSocketContainer()
,如描述在这里,简单地尝试加载其他类和得到的静态实例ContainerProvider
的服务器。
The method looks for the
ContainerProvider
implementation class in the order listed in theMETA-INF/services/javax.websocket.ContainerProvider
file, returning theWebSocketContainer
implementation from theContainerProvider
implementation that is notnull
.
该方法
ContainerProvider
按照META-INF/services/javax.websocket.ContainerProvider
文件中列出的顺序查找实现类,WebSocketContainer
从ContainerProvider
不是的实现返回实现null
。
This, unfortunately, means that your project is not configured correctly. Double check to make sure this file is included in your project's build path.
不幸的是,这意味着您的项目配置不正确。仔细检查以确保此文件包含在项目的构建路径中。
If other projects you are looking at are using the Maven dependency you described, I would try to set up your project to do the same.
如果您正在查看的其他项目正在使用您描述的 Maven 依赖项,我会尝试设置您的项目以执行相同的操作。
Hope this helped!
希望这有帮助!
回答by dlaagniechy
Adding
添加
// https://mvnrepository.com/artifact/org.glassfish.tyrus.bundles/tyrus-standalone-client
compile group: 'org.glassfish.tyrus.bundles', name: 'tyrus-standalone-client', version: '1.9'
// https://mvnrepository.com/artifact/org.glassfish.tyrus.bundles/tyrus-standalone-client
编译组:'org.glassfish.tyrus.bundles',名称:'tyrus-standalone-client',版本:'1.9'
to my build.gradlefile worked for me.
我的build.gradle文件对我有用。