Can't start WebSocket container with Tomcat and Maven's tomcat7-websocket plug-in

java, maven, tomcat, tomcat7, websocket

Solution

You need to use this dependency and marked it as provided (and not the one coming from org.apache.tomcat never included tomcat dependency as it's all provided by the container). That's similar to servlet-api:

<dependency>
  <groupId>javax.websocket</groupId>
  <artifactId>javax.websocket-api</artifactId>
  <version>1.0</version>
  <scope>provided</scope>
</dependency>

Problem

I am trying to get a Tomcat server (7.0.54) to support WebSocket and having a hard time deploying it. I have a simple endpoint: `@ServerEndpoint(value = "/test") public class TestEndpoint { ` In order to have this endpoint processed, I need to include a container (which uses ServiceLoader to start, introspect all the classes with endpoint annotations, etc...). I use the following: ` <dependency> <groupId>org.apache.tomcat</groupId> <artifactId>tomcat7-websocket</artifactId> <version>7.0.47</version> </dependency> ` However, `mvn tomcat7:run` then fails to start with: `SEVERE: Parse error in application web.xml file at jndi:/localhost/WEB-INF/web.xml org.xml.sax.SAXParseException; systemId: jndi:/localhost/WEB-INF/web.xml; lineNumber: 13; columnNumber: 12; Error at (13, 12) : org.apache.catalina.deploy.WebXml addFilter ` If instead, I specify the scope as `system` and I point it to my local file system: ` <dependency> <groupId>org.apache.tomcat</groupId> <artifactId>tomcat7-websocket</artifactId> <version>7.0.47</version> <scope>system</scope> <systemPath>${somewhere}/tomcat7-websocket-7.0.54.jar</systemPath> </dependency> ` ... then everything works fine, but of course, this can't be reliably deployed on a live server. What can I do to start my WebSocket container properly?

Original source