java – Jetty WebSockets的Jar / Class问题
作者:互联网
我有WebSockets的问题.使用Jetty 9.1.0和Maven由Java开发环境IntelliJ IDEA Community Edition 12.1.6执行.
我创建了两个类(下面的代码).
WsHandler类:
public class WsHandler extends WebSocketHandler {
private final ConcurrentMap<String, Set<EventWebSocket>> eventsSubscribers = new ConcurrentHashMap<>();
@Override
public WebSocket doWebSocketConnect(HttpServletRequest request, String protocol) {
return new EventWebSocket();
}
private void fireEvent(String eventName) {
Set<EventWebSocket> subscribers = eventsSubscribers.get(eventName);
System.out.println("Event " + eventName + " was occurred. Subscribers " + subscribers);
if (subscribers != null) {
for (EventWebSocket webSocket : subscribers) {
webSocket.onEvent(eventName);
}
}
}
public final class EventWebSocket implements WebSocket.OnTextMessage {
private Connection connection;
private List<String> subscribedEvents = new LinkedList();
@Override
public void onOpen(Connection connection) {
System.out.println("Open connection " + connection);
this.connection = connection;
}
@Override
public void onMessage(String data) {
System.out.println("Process msg: " + data);
if (data.isEmpty()) return;
if (data.startsWith("Sub")) { // subscribe
if (data.length() < 5) return;
String eventName = data.split(":")[1]; // subscribing message format "Sub:EventName"
Set<EventWebSocket> subscribers = eventsSubscribers.get(eventName);
// double-check idiom for lazy initialization
if (subscribers == null) {
synchronized (EventHandler.class) {
if (eventsSubscribers.get(eventName) == null) {
subscribers = new CopyOnWriteArraySet<>();
eventsSubscribers.putIfAbsent(eventName, subscribers);
}
}
}
subscribers.add(this);
subscribedEvents.add(eventName);
} else if (data.startsWith("Fire")) { // fire event
if (data.length() < 6) return;
String eventName = data.split(":")[1]; // Fire event message format "Fire:EventName"
fireEvent(eventName);
} else {
try {
connection.sendMessage("Unknown command: " + data);
} catch (IOException ex) {
System.err.println("Ooops: " + ex + ". Close connection " + connection);
}
}
}
public void onEvent(String eventName) {
try {
connection.sendMessage("Event " + eventName + " was occurred");
} catch (IOException ex) {
System.err.println("Ooops: " + ex + ". Close connection " + connection);
}
}
@Override
public void onClose(int closeCode, String message) {
System.out.println("Close connection " + connection);
// remove from subscribers
for (String eventName : subscribedEvents) {
eventsSubscribers.get(eventName).remove(this);
}
}
}}
SimpleEchoClien类:
public class SimpleEchoClient {
public static void main(String[] args) throws Exception {
Server server = new Server(8080);
WsHandler handler = new WsHandler();
server.setHandler(handler);
server.start();
server.join();
}}
运行并获取错误:
"C:\Program Files\Java\jdk1.7.0_17\bin\java" -Didea.launcher.port=7532 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 12.1.6\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.7.0_17\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.7.0_17\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.7.0_17\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.7.0_17\jre\lib\jce.jar;C:\Program Files\Java\jdk1.7.0_17\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.7.0_17\jre\lib\jfxrt.jar;C:\Program Files\Java\jdk1.7.0_17\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.7.0_17\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.7.0_17\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.7.0_17\jre\lib\resources.jar;C:\Program Files\Java\jdk1.7.0_17\jre\lib\rt.jar;C:\Program Files\Java\jdk1.7.0_17\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.7.0_17\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.7.0_17\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.7.0_17\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.7.0_17\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.7.0_17\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.7.0_17\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.7.0_17\jre\lib\ext\zipfs.jar;C:\Users\Alexandr.Alexandr-PC\Documents\java\Shooter\target\classes;C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 12.1.6\lib\junit-4.10.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\freemarker\freemarker\2.3.19\freemarker-2.3.19.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-server\9.1.0.M0\jetty-server-9.1.0.M0.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\javax\servlet\javax.servlet-api\3.1.0\javax.servlet-api-3.1.0.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-http\9.1.0.M0\jetty-http-9.1.0.M0.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-util\9.1.0.M0\jetty-util-9.1.0.M0.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-io\9.1.0.M0\jetty-io-9.1.0.M0.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-webapp\9.1.0.M0\jetty-webapp-9.1.0.M0.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-xml\9.1.0.M0\jetty-xml-9.1.0.M0.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-servlet\9.1.0.M0\jetty-servlet-9.1.0.M0.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-security\9.1.0.M0\jetty-security-9.1.0.M0.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-rewrite\9.1.0.M0\jetty-rewrite-9.1.0.M0.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-client\9.1.0.M0\jetty-client-9.1.0.M0.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\mockito\mockito-all\1.8.4\mockito-all-1.8.4.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\seleniumhq\selenium\selenium-java\2.4.0\selenium-java-2.4.0.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\seleniumhq\selenium\selenium-android-driver\2.4.0\selenium-android-driver-2.4.0.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\seleniumhq\selenium\selenium-remote-driver\2.4.0\selenium-remote-driver-2.4.0.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\cglib\cglib-nodep\2.1_3\cglib-nodep-2.1_3.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\json\json\20080701\json-20080701.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\seleniumhq\selenium\selenium-api\2.4.0\selenium-api-2.4.0.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\com\google\guava\guava\r09\guava-r09.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\apache\httpcomponents\httpclient\4.0.2\httpclient-4.0.2.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\apache\httpcomponents\httpcore\4.0.1\httpcore-4.0.1.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\commons-logging\commons-logging\1.1.1\commons-logging-1.1.1.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\commons-codec\commons-codec\1.4\commons-codec-1.4.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\seleniumhq\selenium\selenium-chrome-driver\2.4.0\selenium-chrome-driver-2.4.0.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\seleniumhq\selenium\selenium-htmlunit-driver\2.4.0\selenium-htmlunit-driver-2.4.0.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\net\sourceforge\htmlunit\htmlunit\2.8\htmlunit-2.8.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\xalan\xalan\2.7.1\xalan-2.7.1.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\xalan\serializer\2.7.1\serializer-2.7.1.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\xml-apis\xml-apis\1.3.04\xml-apis-1.3.04.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\commons-collections\commons-collections\3.2.1\commons-collections-3.2.1.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\commons-lang\commons-lang\2.4\commons-lang-2.4.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\apache\httpcomponents\httpmime\4.0.1\httpmime-4.0.1.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\apache\james\apache-mime4j\0.6\apache-mime4j-0.6.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\net\sourceforge\htmlunit\htmlunit-core-js\2.8\htmlunit-core-js-2.8.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\xerces\xercesImpl\2.9.1\xercesImpl-2.9.1.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\net\sourceforge\nekohtml\nekohtml\1.9.14\nekohtml-1.9.14.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\net\sourceforge\cssparser\cssparser\0.9.5\cssparser-0.9.5.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\w3c\css\sac\1.3\sac-1.3.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\commons-io\commons-io\2.0.1\commons-io-2.0.1.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\seleniumhq\selenium\selenium-firefox-driver\2.4.0\selenium-firefox-driver-2.4.0.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\seleniumhq\selenium\selenium-ie-driver\2.4.0\selenium-ie-driver-2.4.0.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\net\java\dev\jna\jna\3.2.3\jna-3.2.3.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\seleniumhq\selenium\selenium-iphone-driver\2.4.0\selenium-iphone-driver-2.4.0.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\seleniumhq\selenium\selenium-support\2.4.0\selenium-support-2.4.0.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\junit\junit\4.11\junit-4.11.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-websocket\7.4.4.v20110707\jetty-websocket-7.4.4.v20110707.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\javax\servlet\servlet-api\2.5\servlet-api-2.5.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 12.1.6\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain servlets.SimpleEchoClient
2013-12-01 00:52:53.727:INFO:oejs.Server:main: jetty-9.1.0.M0
2013-12-01 00:52:53.747:WARN:oejuc.AbstractLifeCycle:main: FAILED servlets.WsHandler@267a1e1c: java.lang.NoClassDefFoundError: org/eclipse/jetty/http/HttpException
java.lang.NoClassDefFoundError: org/eclipse/jetty/http/HttpException
at org.eclipse.jetty.websocket.WebSocketHandler.doStart(WebSocketHandler.java:76)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:118)
at org.eclipse.jetty.server.Server.start(Server.java:342)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:100)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:58)
at org.eclipse.jetty.server.Server.doStart(Server.java:290)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
at servlets.SimpleEchoClient.main(SimpleEchoClient.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by:
java.lang.ClassNotFoundException: org.eclipse.jetty.http.HttpException
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at org.eclipse.jetty.websocket.WebSocketHandler.doStart(WebSocketHandler.java:76)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:118)
at org.eclipse.jetty.server.Server.start(Server.java:342)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:100)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:58)
at org.eclipse.jetty.server.Server.doStart(Server.java:290)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
at servlets.SimpleEchoClient.main(SimpleEchoClient.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
2013-12-01 00:52:53.748:WARN:oejuc.AbstractLifeCycle:main: FAILED org.eclipse.jetty.server.Server@1b4ed400: java.lang.NoClassDefFoundError: org/eclipse/jetty/http/HttpException
java.lang.NoClassDefFoundError: org/eclipse/jetty/http/HttpException
at org.eclipse.jetty.websocket.WebSocketHandler.doStart(WebSocketHandler.java:76)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:118)
at org.eclipse.jetty.server.Server.start(Server.java:342)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:100)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:58)
at org.eclipse.jetty.server.Server.doStart(Server.java:290)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
at servlets.SimpleEchoClient.main(SimpleEchoClient.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
问题可能与什么有关?提前致谢.
解决方法:
首先,你的命令行,分解,使其可读:
"C:\Program Files\Java\jdk1.7.0_17\bin\java"
-Didea.launcher.port=7532
"-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 12.1.6\bin"
-Dfile.encoding=UTF-8
-classpath "C:\Program Files\Java\jdk1.7.0_17\jre\lib\charsets.jar
C:\Program Files\Java\jdk1.7.0_17\jre\lib\deploy.jar
C:\Program Files\Java\jdk1.7.0_17\jre\lib\javaws.jar
C:\Program Files\Java\jdk1.7.0_17\jre\lib\jce.jar
C:\Program Files\Java\jdk1.7.0_17\jre\lib\jfr.jar
C:\Program Files\Java\jdk1.7.0_17\jre\lib\jfxrt.jar
C:\Program Files\Java\jdk1.7.0_17\jre\lib\jsse.jar
C:\Program Files\Java\jdk1.7.0_17\jre\lib\management-agent.jar
C:\Program Files\Java\jdk1.7.0_17\jre\lib\plugin.jar
C:\Program Files\Java\jdk1.7.0_17\jre\lib\resources.jar
C:\Program Files\Java\jdk1.7.0_17\jre\lib\rt.jar
C:\Program Files\Java\jdk1.7.0_17\jre\lib\ext\access-bridge-64.jar
C:\Program Files\Java\jdk1.7.0_17\jre\lib\ext\dnsns.jar
C:\Program Files\Java\jdk1.7.0_17\jre\lib\ext\jaccess.jar
C:\Program Files\Java\jdk1.7.0_17\jre\lib\ext\localedata.jar
C:\Program Files\Java\jdk1.7.0_17\jre\lib\ext\sunec.jar
C:\Program Files\Java\jdk1.7.0_17\jre\lib\ext\sunjce_provider.jar
C:\Program Files\Java\jdk1.7.0_17\jre\lib\ext\sunmscapi.jar
C:\Program Files\Java\jdk1.7.0_17\jre\lib\ext\zipfs.jar
C:\Users\Alexandr.Alexandr-PC\Documents\java\Shooter\target\classes
C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 12.1.6\lib\junit-4.10.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\freemarker\freemarker\2.3.19\freemarker-2.3.19.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-server\9.1.0.M0\jetty-server-9.1.0.M0.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\javax\servlet\javax.servlet-api\3.1.0\javax.servlet-api-3.1.0.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-http\9.1.0.M0\jetty-http-9.1.0.M0.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-util\9.1.0.M0\jetty-util-9.1.0.M0.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-io\9.1.0.M0\jetty-io-9.1.0.M0.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-webapp\9.1.0.M0\jetty-webapp-9.1.0.M0.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-xml\9.1.0.M0\jetty-xml-9.1.0.M0.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-servlet\9.1.0.M0\jetty-servlet-9.1.0.M0.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-security\9.1.0.M0\jetty-security-9.1.0.M0.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-rewrite\9.1.0.M0\jetty-rewrite-9.1.0.M0.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-client\9.1.0.M0\jetty-client-9.1.0.M0.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\mockito\mockito-all\1.8.4\mockito-all-1.8.4.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\seleniumhq\selenium\selenium-java\2.4.0\selenium-java-2.4.0.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\seleniumhq\selenium\selenium-android-driver\2.4.0\selenium-android-driver-2.4.0.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\seleniumhq\selenium\selenium-remote-driver\2.4.0\selenium-remote-driver-2.4.0.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\cglib\cglib-nodep\2.1_3\cglib-nodep-2.1_3.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\json\json\20080701\json-20080701.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\seleniumhq\selenium\selenium-api\2.4.0\selenium-api-2.4.0.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\com\google\guava\guava\r09\guava-r09.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\apache\httpcomponents\httpclient\4.0.2\httpclient-4.0.2.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\apache\httpcomponents\httpcore\4.0.1\httpcore-4.0.1.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\commons-logging\commons-logging\1.1.1\commons-logging-1.1.1.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\commons-codec\commons-codec\1.4\commons-codec-1.4.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\seleniumhq\selenium\selenium-chrome-driver\2.4.0\selenium-chrome-driver-2.4.0.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\seleniumhq\selenium\selenium-htmlunit-driver\2.4.0\selenium-htmlunit-driver-2.4.0.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\net\sourceforge\htmlunit\htmlunit\2.8\htmlunit-2.8.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\xalan\xalan\2.7.1\xalan-2.7.1.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\xalan\serializer\2.7.1\serializer-2.7.1.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\xml-apis\xml-apis\1.3.04\xml-apis-1.3.04.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\commons-collections\commons-collections\3.2.1\commons-collections-3.2.1.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\commons-lang\commons-lang\2.4\commons-lang-2.4.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\apache\httpcomponents\httpmime\4.0.1\httpmime-4.0.1.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\apache\james\apache-mime4j\0.6\apache-mime4j-0.6.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\net\sourceforge\htmlunit\htmlunit-core-js\2.8\htmlunit-core-js-2.8.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\xerces\xercesImpl\2.9.1\xercesImpl-2.9.1.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\net\sourceforge\nekohtml\nekohtml\1.9.14\nekohtml-1.9.14.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\net\sourceforge\cssparser\cssparser\0.9.5\cssparser-0.9.5.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\w3c\css\sac\1.3\sac-1.3.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\commons-io\commons-io\2.0.1\commons-io-2.0.1.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\seleniumhq\selenium\selenium-firefox-driver\2.4.0\selenium-firefox-driver-2.4.0.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\seleniumhq\selenium\selenium-ie-driver\2.4.0\selenium-ie-driver-2.4.0.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\net\java\dev\jna\jna\3.2.3\jna-3.2.3.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\seleniumhq\selenium\selenium-iphone-driver\2.4.0\selenium-iphone-driver-2.4.0.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\seleniumhq\selenium\selenium-support\2.4.0\selenium-support-2.4.0.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\junit\junit\4.11\junit-4.11.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-websocket\7.4.4.v20110707\jetty-websocket-7.4.4.v20110707.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\javax\servlet\servlet-api\2.5\servlet-api-2.5.jar
C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 12.1.6\lib\idea_rt.jar"
com.intellij.rt.execution.application.AppMain servlets.SimpleEchoClient
并且是您程序的第一行输出
2013-12-01 00:52:53.727:INFO:oejs.Server:main: jetty-9.1.0.M0
你有很多事情需要照顾.
>您正在运行Jetty的混合版本.您的码头腹围位于7.4.4.v20110707,而Jetty的其余部分位于9.1.0.M0.
>您应该升级到Jetty 9.1的最终(非里程碑,非发布候选版本)版本,以获得最成熟的websocket实现.那将是码头9.1.0.v20131115
>您的代码示例适用于websocket的早期草案实现,并显示您正在查看一些非常古老的代码示例.会阻止你使用那个已经弃用的API.
>您的Java版本已经过时了. 1.7更新17在6月份过期(是的,Java版本到期.阅读发行说明.例如:u40 expires on 12/10/2013和u45 expires on 1/14/2014)
>使用Modern Jetty WebSocket API或javax.websocket标准API.
Modern Jetty WebSocket API
示例项目已设置为:
您需要的maven依赖项:
<!-- To write basic websockets against -->
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-api</artifactId>
<version>9.1.0.v20131115</version>
</dependency>
<!-- To run websockets in embedded server -->
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-server</artifactId>
<version>9.1.0.v20131115</version>
</dependency>
<!-- To run websockets client -->
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-client</artifactId>
<version>9.1.0.v20131115</version>
</dependency>
查看示例代码.
> EventServer.java
– 这是jetty嵌入式服务器代码,用于初始化处理程序树ServletContext.它将EventServlet映射到路径规范“/ events / *”
> EventServlet.java
– 这只是简单地将EventSocket注册到Servlet(对于后台,WebSocketServletFactory有一个简单的默认实现WebSocketCreator
,只支持1个websocket..register(Class<?>)调用只是告诉这个默认的WebSocketCreator创建什么WebSocket如果你想要一个更复杂的WebSocketCreator,你可以用你自己的实现调用WebSocketServletFactory.setCreator(WebSocketCreator)
)
> EventSocket.java
– 接收传入事件的实际websocket
> EventClient.java
– 由于您的演示代码被称为客户端,但其中包含服务器代码,我并不真正知道您的计划是什么,所以我也投入了Native Jetty WebSocket客户端示例.
Jetty上的javax.websocket标准API
示例项目已设置为:
您需要的maven依赖项:
<!-- To write basic javax.websocket against -->
<dependency>
<groupId>javax.websocket</groupId>
<artifactId>javax.websocket-api</artifactId>
<version>1.0</version>
</dependency>
<!-- To run javax.websocket in embedded server -->
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>javax-websocket-server-impl</artifactId>
<version>9.1.0.v20131115</version>
</dependency>
<!-- To run javax.websocket client -->
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>javax-websocket-client-impl</artifactId>
<version>9.1.0.v20131115</version>
</dependency>
查看示例代码.
> EventServer.java
– 这与Native API略有不同,因为javax.websocket世界中的所有内容都基于带有发现的Annotations.因此,这个嵌入式服务器建立了一个ServletContextHandler,然后通过调用WebSocketServerContainerInitializer.configureContext(context)初始化javax.websocket层,最后使用ServerContainer
的手册addEndpoint(Class)
.
> EventSocket.java
– 使用javax.websocket的注释,此类都注释为服务器端点和客户端端点,应该接收各种事件的方法也会注释以指示其所需的目的.
> EventClient.java
– 这使用javax.websocket WebSocketContainer(客户端容器)连接到服务器并发送消息. (特别值得注意的是,清理WebSocketContainer生命周期的额外工作.来自JSR-356规范的缺失功能)
祝好运
标签:java,websocket,jetty,embedded-jetty 来源: https://codeday.me/bug/20190714/1459995.html