Cedric Beust
Cedric Beust

Reputation: 15608

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

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?

Upvotes: 3

Views: 2634

Answers (1)

Olivier Lamy
Olivier Lamy

Reputation: 2310

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>

Upvotes: 4

Related Questions