title: Using Websockets in Jetty
body: <p>See <a href="https://stackoverflow.com/questions/32296856/nosuchmethoderror-httpservletrequest-getservletcontext-on-servlet-3-0/32302306#32302306">here</a> for previous question.</p>
  
  <p>I'm trying to set up an application using Websockets and running in Jetty. When I run <a href="https://docs.gradle.org/current/dsl/org.gradle.api.plugins.jetty.JettyRun.html" rel="nofollow noreferrer">gradle jettyRun</a>, however, I get:</p>
  
  <pre><code>javax.servlet.ServletException: Not running on Jetty, WebSocket support unavailable
      at org.eclipse.jetty.websocket.server.WebSocketServerFactory.init(WebSocketServerFactory.java:411)
      at org.eclipse.jetty.websocket.servlet.WebSocketServlet.init(WebSocketServlet.java:136)
      at javax.servlet.GenericServlet.init(GenericServlet.java:241)
      at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:440)
      at org.mortbay.jetty.servlet.ServletHolder.getServlet(ServletHolder.java:339)
      at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
      at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:390)
      at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
      at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
      at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
      at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:440)
      at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)
      at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
      at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
      at org.mortbay.jetty.Server.handle(Server.java:326)
      at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
      at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:926)
      at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:549)
      at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
      at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
      at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)
      at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
  </code></pre>
  
  <p><a href="https://eclipse.org/jetty/documentation/current/jetty-websocket-server-api.html" rel="nofollow noreferrer">This page</a> suggests that Websockets are only available "within the Jetty container", but I would have thought that the Jetty plugin would do so by default. Do I need to reconfigure it somehow?</p>
  
  <p>EDIT: <a href="https://issues.gradle.org/plugins/servlet/mobile#issue/GRADLE-1956" rel="nofollow noreferrer">This issue</a> suggests that the Jetty plugin targets an old (and incompatible-with-websockets) version of Jetty. It's pretty old, though - I don't know if the claim that it's unresolved is still true. I'll try running Jetty directly, rather than through the plugin.</p>