title: Deploy webapps and websockets in jetty
body: <p>I have embedded Jetty into my application. I have one webapp and I successfully deployed that webapp in the Jetty. Now I got another requirement on Websockets. I followed this <a href="https://github.com/jetty-project/embedded-jetty-websocket-examples/blob/master/javax.websocket-example/src/main/java/org/eclipse/jetty/demo/EventSocket.java" rel="nofollow noreferrer">link</a> for deploying websockets in Jetty. After deploying the Websockets into my server the first webapp is not working (the home page is not opening). Here is the image</p>
  
  <p><a href="https://i.stack.imgur.com/plrwt.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/plrwt.jpg" alt="enter image description here"></a></p>
  
  <p>Here is the code (Its very hard to paste the whole code here. So I am pasting the webapp and websocket deployment code).</p>
  
  <p>Webapp Deployment:</p>
  
  <pre><code>List&lt;Handler&gt; handlersList = new ArrayList&lt;Handler&gt;();
  WebAppContext webAppContext = new WebAppContext();
  webAppContext.setResourceBase(webApp.appDir);
  webAppContext.setDescriptor(webApp.appDir + "/WEB-INF/web.xml");
  webAppContext.setContextPath(webApp.contextPath);
  webAppContext.setParentLoaderPriority(true);
  // webAppContext.setWar(webApp.appDir);
  webAppContext.setVirtualHosts(webApp.hostName);
  handlersList.add(webAppContext);
  argNewServer.setHandler(handlersList);
  </code></pre>
  
  <p>WebSocket Deployment:</p>
  
  <pre><code>ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
  context.setContextPath("/echo");
  argServer.setHandler(context);
  
  // Initialize javax.websocket layer
  ServerContainer wscontainer;
  try {
      wscontainer = WebSocketServerContainerInitializer.configureContext(context);
      // Add WebSocket endpoint to javax.websocket layer
      wscontainer.addEndpoint(WebSocketServer.class);
  } catch (ServletException | DeploymentException e) {
      throw new RuntimeException("Exception while adding websocket endpoint: ", e);
  }
  </code></pre>
  
  <p>WebSocketServer.java:</p>
  
  <pre><code>package com.tdg.chat;
  
  import java.io.IOException;
  
  import javax.websocket.CloseReason;
  import javax.websocket.OnClose;
  import javax.websocket.OnError;
  import javax.websocket.OnMessage;
  import javax.websocket.OnOpen;
  import javax.websocket.Session;
  import javax.websocket.server.ServerEndpoint;
  
  @ServerEndpoint(value = "/events/")
  public class WebSocketServer {
      @OnOpen
      public void onWebSocketConnect(Session sess) {
          System.out.println("Socket Connected: " + sess);
      }
  
      @OnMessage
      public void onWebSocketText(Session argSession, String argMessage) throws IOException {
          System.out.println("Received TEXT message: " + argMessage);
          argSession.getBasicRemote().sendText("From Server: ");
      }
  
      @OnClose
      public void onWebSocketClose(CloseReason reason) {
          System.out.println("Socket Closed: " + reason);
      }
  
      @OnError
      public void onWebSocketError(Throwable cause) {
          cause.printStackTrace(System.err);
      }
  }
  </code></pre>
  
  <p>If I include the aforementioned websocket code the actual webapp is not working, but the websocket code is working. </p>
  
  <p>So how to deploy a webapp and websocket in one Jetty server?</p>
  
  <p><strong>Updated:</strong></p>
  
  <p>I tried to include the Websockets in the current webapp itself but I am getting the following exception.</p>
  
  <blockquote>
    <p>java.lang.NullPointerException: null
        at org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer.configureContext(WebSocketServerContainerInitializer.java:65) ~[javax-websocket-server-impl-9.3.6.v20151106.jar:9.3.6.v20151106]
        at com.tdg.daemon.server.RiseServer.getWebappHandlers(RiseServer.java:122) ~[classes/:na]
        at com.tdg.daemon.server.RiseServer.addWebApps(RiseServer.java:77) ~[classes/:na]
        at com.tdg.daemon.server.RiseServer.init(RiseServer.java:59) ~[classes/:na]
        at com.tdg.daemon.server.RiseServerConfiguration.build(RiseServerConfiguration.java:475) ~[classes/:na]
        at com.tdg.daemon.server.launcher.DefaultTdgServerLauncher.start(DefaultTdgServerLauncher.java:78) [classes/:na]
        at com.tdg.daemon.server.launcher.DefaultTdgServerLauncher.main(DefaultTdgServerLauncher.java:140) [classes/:na]
    java.lang.NullPointerException
        at org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer.configureContext(WebSocketServerContainerInitializer.java:65)
        at com.tdg.daemon.server.RiseServer.getWebappHandlers(RiseServer.java:122)
        at com.tdg.daemon.server.RiseServer.addWebApps(RiseServer.java:77)
        at com.tdg.daemon.server.RiseServer.init(RiseServer.java:59)
        at com.tdg.daemon.server.RiseServerConfiguration.build(RiseServerConfiguration.java:475)
        at com.tdg.daemon.server.launcher.DefaultTdgServerLauncher.start(DefaultTdgServerLauncher.java:78)
        at com.tdg.daemon.server.launcher.DefaultTdgServerLauncher.main(DefaultTdgServerLauncher.java:140)
    [] 12/02/2015 17:50:06.985 [main - ] INFO  c.t.d.s.l.DefaultTdgServerLauncher - RiseServer started on port 80 and 443.</p>
  </blockquote>