Search code examples
javascalajettyhttp4s

Why does it show Jetty?


I have built my web app with https://http4s.org/:

object UserSvcServer {

  def stream[F[_]: ConcurrentEffect](implicit T: Timer[F], C: ContextShift[F]): Stream[F, Nothing] = {

    val helloWorldAlg = HelloWorld.impl[F]
    val httpApp = (
      UserSvcRoutes.helloWorldRoutes[F](helloWorldAlg)
      ).orNotFound

    val finalHttpApp = Logger.httpApp(true, true)(httpApp)

    for {

      exitCode <- JettyBuilder[F]
        .bindHttp(8080, "0.0.0.0")
        .mountHttpApp(finalHttpApp, "/")
        .serve
    } yield exitCode
  }.drain

} 

as you can see on the code above, it uses JettyBuilder.

When I start the application, the logs shows:

[main] INFO  o.e.j.util.log - Logging initialized @730ms to org.eclipse.jetty.util.log.Slf4jLog 
[ioapp-compute-0] INFO  o.e.j.s.Server - jetty-9.4.28.v20200408; built: 2020-04-08T17:49:39.557Z; git: ab228fde9e55e9164c738d7fa121f8ac5acd51c9; jvm 11.0.7+10-LTS 
[ioapp-compute-0] INFO  o.h.s.Http4sServlet - Detected Servlet API version 3.1 
[ioapp-compute-0] INFO  o.h.s.Http4sServlet - Using non-blocking servlet I/O with chunk size 4096 
[ioapp-compute-0] INFO  o.e.j.s.h.ContextHandler - Started o.e.j.s.ServletContextHandler@71cc4a24{/,null,AVAILABLE}   

Does it mean, that the web app runs already on Jetty and I do not have to download the jetty server from https://www.eclipse.org/jetty/?

Usually, the war file has to put into the webapps filder:

enter image description here


Solution

  • If you look at build.sbt of http4s you'll see that many of http4s libraries use Jetty as the underlying implementation. For instance http4s-jetty which you most likely use.

    So no, you don't have to download jetty or any other container. If you wanted to make your code require a container you would most likely have to add some extra effort.