Reputation: 63231
I see in numerous places phrases like:
Changing the port in development Add
port in container.Configuration := 8081
to project/build.scala
But where in build.scala? Here is the vanilla build.scala. It is unclear where that addition should go:
object KeywordsBuild extends Build {
val Organization = "com.blazedb"
..
lazy val project = Project (
"keywords",
file("."),
settings = ScalatraPlugin.scalatraSettings ++ scalateSettings ++ Seq(
organization := Organization,
name := Name,
version := Version,
..
libraryDependencies ++= Seq(
"org.scalatra" %% "scalatra" % ScalatraVersion,
..
"javax.servlet" % "javax.servlet-api" % "3.1.0" % "provided"
),
scalateTemplateConfig in Compile <<= (sourceDirectory in Compile){ base =>
Seq(
TemplateConfig(
base / "webapp" / "WEB-INF" / "templates",
Seq.empty, /* default imports should be added here */
Seq(
Binding("context", "_root_.org.scalatra.scalate.ScalatraRenderContext", importMembers = true, isImplicit = true)
), /* add extra bindings here */
Some("templates")
)
Wherever I have tried to put it the following error message happens:
[info] Compiling 1 Scala source to /shared/wfdemo/project/target/scala-2.10/sbt-0.13/classes...
/shared/wfdemo/build.sbt:1: error: not found: value port
port in container.Configuration := 8081
Upvotes: 2
Views: 890
Reputation: 765
create a file JettyLauncher.scala under /src/main/scala :
import org.eclipse.jetty.server.Server
import org.eclipse.jetty.servlet.{DefaultServlet, ServletContextHandler}
import org.eclipse.jetty.webapp.WebAppContext
import org.scalatra.servlet.ScalatraListener
object JettyLauncher {
def main(args: Array[String]) {
val port = System.getProperty("port","8090").toInt
val server = new Server(port)
val context = new WebAppContext()
context setContextPath "/"
context.setResourceBase("src/main/webapp")
context.addEventListener(new ScalatraListener)
context.addServlet(classOf[DefaultServlet], "/")
server.setHandler(context)
server.start
server.join
}
}
make sure your plugins.sbt under project/ has :
addSbtPlugin("com.typesafe.sbt" % "sbt-twirl" % "1.3.13")
addSbtPlugin("org.scalatra.sbt" % "sbt-scalatra" % "1.0.2")
addSbtPlugin("com.earldouglas" % "xsbt-web-plugin" % "4.0.0")
agains sbt = 0.13.16
do an sbt clean compile assembly package (now that you have an sbt-assembly plugin)
run your jar as follows :
java -Dport=8081 -Dname=sameer -jar /Users/sumit/Documents/repos/inner/paytm-insurance-ml-api/serving-layers/model-serving-movies-cp/target/scala-2.11/model-serving-movies-cp-assembly-0.1.jar
This worked for me :
13:11:18.326 [main] INFO o.e.jetty.server.AbstractConnector - Started ServerConnector@509dbdcf{HTTP/1.1,[http/1.1]}{0.0.0.0:8081}
13:11:18.327 [main] INFO org.eclipse.jetty.server.Server - Started @1312ms
Upvotes: 0
Reputation: 63231
The correct way is to add to
build.sbt
So the documentation appears to be incorrect - or at the least misleading.
$cat build.sbt
val myPort = 9090
jetty(port = myPort)
Upvotes: 1