title: How should I load servlets from web.xml with embedded jetty?
body: <p>I am trying to migrate my application from <strong>tomcat</strong> to <strong>embedded jetty</strong>. I have created an entrypoint in web module following some guides (<a href="https://examples.javacodegeeks.com/enterprise-java/jetty/jetty-web-xml-configuration-example/" rel="nofollow noreferrer">this</a>, <a href="https://newfivefour.com/java-jersey-jetty-rest-gradle-tutorial-setup-quick.html" rel="nofollow noreferrer">this</a>, <a href="https://www.eclipse.org/jetty/documentation/current/embedding-jetty.html" rel="nofollow noreferrer">this</a> and etc...). Resulting file is presented below:</p>
  <pre class="lang-scala prettyprint-override"><code>import org.eclipse.jetty.server.Server
  import org.eclipse.jetty.webapp.WebAppContext
  
  object EPILauncher extends App {
    val server: Server = new Server(8080)
    val coolWebApplication = new WebAppContext()
    coolWebApplication.setResourceBase(&quot;warehouse/src/main/webapp/&quot;)
    coolWebApplication.setContextPath(&quot;/api&quot;)
    coolWebApplication.setDescriptor(&quot;warehouse/src/main/webapp/WEB-INF/web.xml&quot;)
    coolWebApplication.setParentLoaderPriority(true)
    server.start()
    System.out.println(&quot;Started!&quot;)
    server.join()
  }
  </code></pre>
  <p>I have following servlet declaration in my <code>web.xml</code> file</p>
  <pre class="lang-xml prettyprint-override"><code>     &lt;servlet&gt;
          &lt;servlet-name&gt;CustomerApplication&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.glassfish.jersey.servlet.ServletContainer&lt;/servlet-class&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;javax.ws.rs.Application&lt;/param-name&gt;
              &lt;param-value&gt;com.xxxx.yyyy.warehouse.web.Root&lt;/param-value&gt;
          &lt;/init-param&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;jersey.config.server.provider.packages&lt;/param-name&gt;
              &lt;param-value&gt;
                  io.swagger.jaxrs.listing,
                  org.owasp.csrfguard.servlet,
                  com.xxxx.yyyy.warehouse.resource
              &lt;/param-value&gt;
          &lt;/init-param&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;jersey.config.server.provider.scanning.recursive&lt;/param-name&gt;
              &lt;param-value&gt;true&lt;/param-value&gt;
          &lt;/init-param&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;jersey.config.servlet.filter.staticContentRegex&lt;/param-name&gt;
              &lt;param-value&gt;.*(html|css|js|eot|svg|ttf|woff)&lt;/param-value&gt;
          &lt;/init-param&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;CustomerApplication&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  </code></pre>
  <p>Package <code>com.xxxx.yyyy.warehouse.resource</code> contains implementations, e.g.:</p>
  <pre class="lang-scala prettyprint-override"><code>@Singleton
  @Path(&quot;/settings&quot;)
  @Api(&quot;/settings&quot;)
  class SettingsResource @Inject()(config: Config) {
    @GET
    @Path(&quot;/version&quot;)
    @Produces(Array(MediaType.APPLICATION_JSON))
    def getBackendVersion(@Context servletContext: ServletContext): Response = {
      val manifestStream = servletContext.getResourceAsStream(&quot;META-INF/MANIFEST.MF&quot;)
      val version: String = Option(manifestStream)
        .map(Utils.using(_) { is =&gt;
          val attrs = new java.util.jar.Manifest(is).getMainAttributes
          val version = attrs.getOrDefault(new Attributes.Name(&quot;Specification-Version&quot;), &quot;local-version&quot;).toString
          val build = attrs.getOrDefault(new Attributes.Name(&quot;Implementation-Version&quot;), &quot;local-build&quot;).toString
          s&quot;$version.$build&quot;
        }).getOrElse(&quot;local-version.local-build&quot;)
      Response.ok(VersionInfo(version)).build()
    }
  }
  </code></pre>
  <p>So, when I run my app and navigate to <code>localhost:8080/api/settings/version</code>, all I see is:</p>
  <pre><code>URI:    /api/settings/version
  STATUS: 404
  MESSAGE:    Not Found
  SERVLET:    -
  </code></pre>
  <p>So, I think that I don't understand some concepts properly. Should I explicitly point in my <code>main</code> method, which servlets I want to use? Can they load automatically from <code>web.xml</code> file?
  Thanks.</p>