Can't find Jetty WebSocket classes after adding the libraries in classpath

怎甘沉沦 提交于 2019-12-23 17:56:28

问题


I'm trying to use Jetty to communicate with a remote Server, using websockets. I'm developing it in Eclipse, but i can't compile any sample code. That's what i've done

I downloaded the latest version of Jetty, and i've added start.jar in the classpath. That's what i've included in the sample class

import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose;

and some more. The problem is that Eclipse can't resolve those imports. What should i do?


回答1:


Remove the start.jar from your project, that's just a bootstrap jar for starting the standalone Jetty distribution.

The JARs you need are in the ${jetty.dist}/lib/websockets/ directory.

[joakim@lapetus jetty-distribution-9.0.4.v20130625]$ ls -1 lib/websocket/
websocket-api-9.0.4.v20130625.jar
websocket-client-9.0.4.v20130625.jar
websocket-common-9.0.4.v20130625.jar
websocket-server-9.0.4.v20130625.jar
websocket-servlet-9.0.4.v20130625.jar

All WebSocket Apps

Always include in your project:

  • lib/websocket/websocket-api-9.0.4.v20130625.jar

WebSocket Client Requirements

Add the following to your project:

  • lib/websocket/websocket-client-9.0.4.v20130625.jar
  • lib/websocket/websocket-common-9.0.4.v20130625.jar
  • lib/jetty-io-9.0.4.v20130625.jar
  • lib/jetty-util-9.0.4.v20130625.jar

WebSocket Servlet Requirements

If you are writing a WebSocket server that will hook into your WAR/WebApp, then you'll need:

  • websocket-servlet-9.0.4.v20130625.jar

You will never need websocket-server-9.0.4.v20130625.jar as that is an internal / implementation specific JAR that the Jetty Server uses to provide its support for WebSockets.




回答2:


Please go thru the client API The jar listed there must be in your classpath.



来源:https://stackoverflow.com/questions/17956357/cant-find-jetty-websocket-classes-after-adding-the-libraries-in-classpath

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