Pom.xml ( Although the Maven TOMCAT7 plugin is configured, but the Web service is started directly from Maven, the WebSocket service cannot start.) You want to deploy the Web service to TOMCAT7 server. You can package the war directly, or you can introduce TOMCAT7 in the development tools)
<project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "http://www.w3.org/2001/ Xmlschema-instance " xsi:schemalocation=" http// Maven.apache.org/pom/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd "> < modelversion>4.0.0</modelversion> <groupid>web</groupid> <artifactid>web</artifactid> <packaging>war</ packaging> <version>1.0-snapshot</version> < name>web maven webapp</name> <url>http://maven.apache.org</ url> <dependencies> < Dependency> <groupid> javax.websocket</groupid> <artifactid>javax.websocket-api</artifactid> <version>1.1</version> <scope>provided</scope> </dependency> </dependencies> <build> <finalname>web</ finalname> <plugins> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId> Tomcat7-maven-plugin</artifactid>&nbSp; <version> 2.1</version> <configuration> <port>8077</port> <path>/web</path > <uriEncoding>UTF-8</uriEncoding> <finalName>web</finalName> <server>tomcat7</server> </configuration> </ Plugin> </plugins> </build ></project>
websocket.server.simpleserver
package websocket.server;import javax.websocket.*;import javax.websocket.server.serverendpoint; import java.io.ioexception;import java.util.logging.logger;/** * created by administrator on 2016/4/17. */@ServerEndpoint ("/simplewebsocket") public class Simpleserver { private logger logger = logger.getlogger ( This.getclass (). GetName ()); @OnOpen public void onopen (session session) { logger.info ("websocket open ... "); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;SYSTEM.OUT.PRINTLN (session); } /** * connection Close method of call */ @OnClose public void onclose () { loggEr.info ("websocket close .... "); } @OnError public void onerror (throwable e) { logger.severe ("error~~~~" +e.getmessage ()); } /** * methods that are called after a client message is received * @param message Messages sent by clients * @param session Optional Parameters */ @OnMessage public void onmessage (string Message, session session) throws IOException { logger.info ("receive the message from client [" +message+ "]"); session.getbasicremote (). SendText ("The server received information from the client:" +message); }}
simple.html
<! doctype html>
TOMCAT7 Build WebSocket Service