A scala shim for running embedded jetty (http only currently)
Add the following lines to your build.sbt
resolvers += "Tim Tennant's repo" at "http://dl.bintray.com/timt/repo/"
val jettyVersion="9.2.10.v20150310"
libraryDependencies ++= Seq(
"io.shaka" %% "scala-embedded-jetty" % "28"
"io.shaka" %% "naive-http" % "78",
"org.eclipse.jetty" % "jetty-webapp" % jettyVersion,
"org.eclipse.jetty" % "jetty-plus" % jettyVersion,
"org.eclipse.jetty" % "jetty-servlets" % jettyVersion,
Starting a server
import io.shaka.jetty.EmbeddedJetty
val embeddedJetty = jetty.start() //Start on some free port
...
val embeddedJetty = jetty(1234).start() //Start on port 1234
Customise configuration
import io.shaka.jetty.JettyConfiguration
val jettyConfiguration = JettyConfiguration(port = 1234, logsDirectory = "src/resource/logs")
val embeddedJetty = jetty(jettyConfiguration).start()
Stopping the server
embeddedJetty.stop()
Providing a custom context handler
io.shaka.http.Response.respond
io.shaka.http.Request
jetty
.addHandler("/my-context", (request: Request) => {
respond("<h1>Hello World</h1>".getBytes)
})
.start()
For more examples see
Apache License 2.0