Main.scala 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. package code
  2. import org.eclipse.jetty.server.Server
  3. import org.eclipse.jetty.webapp.WebAppContext
  4. import org.streum.configrity._
  5. import util.control.Exception._
  6. import db._
  7. object Main extends App {
  8. val opts = new Options(args)
  9. val defaults = new Configuration(Map[String, String](
  10. "db.host" -> "localhost:3306",
  11. "db.name" -> "hello_world",
  12. "db.user" -> "benchmarkdbuser",
  13. "db.pass" -> "benchmarkdbpass",
  14. "http.port" -> "8080"
  15. ))
  16. val config = defaults ++ allCatch.opt(Configuration.load("server.conf")).getOrElse(Configuration()) ++ Configuration(opts.properties)
  17. // initialize the db
  18. DB
  19. val server = new Server(config[Int]("http.port"))
  20. val src = new java.io.File("src")
  21. if (src.exists && src.isDirectory) {
  22. // dev mode
  23. server.setHandler(new WebAppContext("src/main/resources/", "/"))
  24. } else {
  25. // runnable jar
  26. server.setHandler(new WebAppContext(getClass.getClassLoader.getResource("WEB-INF/web.xml").toExternalForm.stripSuffix("WEB-INF/web.xml"), "/"))
  27. // setting lift's production mode
  28. System.setProperty("run.mode", "production")
  29. }
  30. server.start()
  31. }