Pages

Wednesday, January 04, 2012

Run Jetty in eclipse with scalatra

Though this is very simple and straight forward, there is no direct answer to this question on internet. You can run any webapp in eclipse using this approach, not necessarily with scalatra. The code is available for Lift web framework and works well with scalatra too.

import org.eclipse.jetty.server.Server
import org.eclipse.jetty.webapp.WebAppContext

object RunWebApp {
def main(args: Array[String]) {
val server = new Server(9080)
val context: WebAppContext = new WebAppContext();
context.setServer(server)
context.setContextPath("/");
context.setWar("src/main/webapp")
server.setHandler(context);

try {
println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP")
server.start()
server.join()
} catch {
case ex: Exception => {
ex.printStackTrace()
System.exit(1)
}
}
}
}

No comments:

Post a Comment