8
votes

I have a server, which shall serve some web content as a part of it's duties. It was working using embedded Jetty, and I want to add some Lift's beauty to it (templates, actors, etc).

The problem is all lift examples use Jetty as a container. Is there a way to start Lift in my embedded Jetty? And if yes, how?

1

1 Answers

5
votes

Found the answer: RunWebApp.scala

import _root_.org.mortbay.jetty.Connector
import _root_.org.mortbay.jetty.Server
import _root_.org.mortbay.jetty.webapp.WebAppContext
import org.mortbay.jetty.nio._

object RunWebApp extends Application {
  val server = new Server
  val scc = new SelectChannelConnector
  scc.setPort(8080)
  server.setConnectors(Array(scc))

  val context = new WebAppContext()
  context.setServer(server)
  context.setContextPath("/")
  context.setWar("src/main/webapp")

  server.addHandler(context)

  try {
    println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP")
    server.start()
    while (System.in.available() == 0) {
      Thread.sleep(5000)
    }
    server.stop()
    server.join()
  } catch {
    case exc : Exception => {
      exc.printStackTrace()
      System.exit(100)
    }
  }
}

My only problem now is to build this with Lift 2.4, Scala 2.9.1 and Eclipse Jetty - currently I can find only artifacts for Lift 2.3, Scala 2.8.1 and Mortbay Jetty.