Websocket Client Could not find an implementation class

北城余情 提交于 2021-02-06 15:24:06

问题


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).

To remedy this I downloaded the oracle-weblogic-7.9.jar but the problem persists.

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?

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)

回答1:


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.

hope this will help you.




回答2:


I think the RuntimeException you are experiencing is fortunately not generated by any direct coding fault of your own.

The method getWebSocketContainer(), as described here, simply tries to load other classes and get the static instance of the ContainerProvider in the server.

The method looks for the ContainerProvider implementation class in the order listed in the META-INF/services/javax.websocket.ContainerProvider file, returning the WebSocketContainer implementation from the ContainerProvider implementation that is not 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.

Hope this helped!




回答3:


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'

to my build.gradle file worked for me.



来源:https://stackoverflow.com/questions/27751630/websocket-client-could-not-find-an-implementation-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!