我正在用Java测试websocket客户端
public class MainCallClient {
public Session session;
protected void start()
{
try {
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
String uri = 'ws://localhost:8080/testCrowdListener3_WSwebsockServer/WSwebsocket';
session = container.connectToServer(WebsocketClient2.class, URI.create(uri));
} catch (DeploymentException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
MainCallClient client = new MainCallClient();
client.start();
String message = 'no parmeter';
if (args != null && args.length > 0) {
message = args[0];
}
try {
client.session.getBasicRemote().sendText(message);
client.session.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
当我跑步时
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
收到错误消息
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/juli/logging/LogFactory
at org.apache.tomcat.websocket.WsWebSocketContainer.<init>(WsWebSocketContainer.java:120)
at org.apache.tomcat.websocket.WsContainerProvider.getContainer(WsContainerProvider.java:26)
at javax.websocket.ContainerProvider.getWebSocketContainer(ContainerProvider.java:67)
at MainCallClient.start(MainCallClient.java:16)
at MainCallClient.main(MainCallClient.java:35)
Caused by: java.lang.ClassNotFoundException: org.apache.juli.logging.LogFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 5 more
我只使用apache-tomcat-8.0.38并添加库。我在Java构建路径中添加tyrus-standalone-client-1.13.1.jar。同样的错误。