10

这听起来很基本,但实际上花了我一整天的时间:我想改变以改变在开发中运行 scalatra 的端口。我从 hello world g8 模板开始,并从那里开始构建。

这是我到目前为止所尝试的:

更改 build.scala 中的端口,ala 文档: http ://www.scalatra.org/guides/deployment/configuration.html 这不会编译,因为端口未定义。

更改 build.scala 中的端口,这两个示例:https:gist.github.com dozed 58af6cfbfe721a562a48 https://github.com/JamesEarlDouglas/xsbt-web-plugin/blob/master/src/sbt-test/web/ servlet/project/Build.scala 同样的问题:端口未定义

重新定义入口点,ala http: www.scalatra.org guides deployment Standalone.html 仍然在端口 8080 上运行

在引导程序中更改 init 参数,ala http: www.scalatra.org guides deployment configuration.html 仍然在端口 8080 上运行

任何帮助表示赞赏。由于某种原因,我不能发布超过 2 个链接,所以用正斜杠替换空格以跟随 url。

这是我的 build.scala 以防万一。

import sbt._
import Keys._
import org.scalatra.sbt._
import org.scalatra.sbt.PluginKeys._
import com.mojolly.scalate.ScalatePlugin._
import ScalateKeys._
import com.earldouglas.xsbtwebplugin._
import WebPlugin._

object YesManBuild extends Build {
  val Organization = "com.prezi"
  val Name = "Yes Man"
  val Version = "0.1.0-SNAPSHOT"
  val ScalaVersion = "2.10.2"
  val ScalatraVersion = "2.2.1"

  //def Conf = config("container")

  lazy val project = Project (
    "yes-man",
    file("."),
    settings = Defaults.defaultSettings ++ ScalatraPlugin.scalatraWithJRebel ++ scalateSettings ++ Seq(
      //port in Conf := 8081,
      mainClass := Some("com.prezi.eureka.JettyLauncher.main"),
      organization := Organization,
      name := Name,
      version := Version,
      scalaVersion := ScalaVersion,
      resolvers += Classpaths.typesafeReleases,
      libraryDependencies ++= Seq(
        "org.slf4j" % "slf4j-log4j12" % "1.7.5",
        "com.netflix.eureka" % "eureka-client" % "1.1.97",
        "com.netflix.ribbon" % "ribbon-httpclient" % "0.1.10",
        "com.netflix.ribbon" % "ribbon-eureka" % "0.1.11",
        "org.scalatra" %% "scalatra" % ScalatraVersion,
        "org.scalatra" %% "scalatra-scalate" % ScalatraVersion,
        "org.scalatra" %% "scalatra-specs2" % ScalatraVersion % "test",
        "ch.qos.logback" % "logback-classic" % "1.0.6" % "runtime",
        "org.eclipse.jetty" % "jetty-webapp" % "8.1.8.v20121106" % "container",
        "org.eclipse.jetty.orbit" % "javax.servlet" % "3.0.0.v201112011016" % "container;provided;test" artifacts (Artifact("javax.servlet", "jar", "jar")),
        "org.eclipse.jetty.aggregate" % "jetty-all" % "9.0.4.v20130625"
      ),
      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")
          )
        )
      }
    )
  )
}

多谢你们,

〜埃里克

4

3 回答 3

15

23.01.2016 更新:scalatra-sbt使用 xsbt-web-plugin 2.0.4 并更改了一些设置。您可以在此处找到 xsbt-web-plugin 文档(相关说明:可在https://github.com/scalatra/scalatra-in-action中找到 xsbt-web-plugin、sbt-web、docker 和独立构建的集成,请参见第 9 章-* 目录)。

对于 Scalatra 应用程序,这意味着:

  • 使用jetty:startjetty:stop而不是容器:开始,容器:停止
  • 使能够JettyPlugin
  • 使用新键,例如containerPort in Jetty := 8090, target in webappPrepare,sourceDirectory in webappPrepare
  • 仅基于 .scala 的 SBT 构建定义:使用正确的导入来导入插件和设置密钥

.sbt 构建定义:

organization := "org.foo"
name := "My build"
version := "0.1.0-SNAPSHOT"
scalaVersion := "2.11.6"

val ScalatraVersion = "2.4.0"

libraryDependencies ++= Seq(
  "org.scalatra" %% "scalatra" % ScalatraVersion,
  "org.scalatra" %% "scalatra-specs2" % ScalatraVersion % "test",
  "com.typesafe" % "config" % "1.2.1",
  "ch.qos.logback" % "logback-classic" % "1.1.3" % "runtime",
  "javax.servlet" % "javax.servlet-api" % "3.1.0" % "provided"
)

enablePlugins(JettyPlugin)

containerPort in Jetty := 8090

基于 .scala 的 SBT 构建定义确实没有那么神奇,我们需要导入插件及其设置:

import sbt._
import Keys._

import org.scalatra.sbt._

import com.earldouglas.xwp.JettyPlugin
import com.earldouglas.xwp.JettyPlugin.autoImport._
import com.earldouglas.xwp.ContainerPlugin.autoImport._

enablePlugins(JettyPlugin)带有自定义端口的实际构建定义:

object MyBuild extends Build {
  val Organization = "org.foo"
  val Name = "My Build"
  val Version = "0.1.0-SNAPSHOT"
  val ScalaVersion = "2.11.6"
  val ScalatraVersion = "2.4.0"

  val mySettings =
    ScalatraPlugin.scalatraSettings ++ Seq(
      organization := Organization,
      name := Name,
      version := Version,
      scalaVersion := ScalaVersion,
      libraryDependencies ++= Seq(
        "org.scalatra" %% "scalatra" % ScalatraVersion,
        "org.scalatra" %% "scalatra-specs2" % ScalatraVersion % "test",
        "com.typesafe" % "config" % "1.2.1",
        "ch.qos.logback" % "logback-classic" % "1.1.3" % "runtime",
        "javax.servlet" % "javax.servlet-api" % "3.1.0" % "provided"
      ),
      containerPort in Jetty := 8090
    )

  lazy val project = Project("chapter09", file("."))
    .enablePlugins(JettyPlugin)
    .settings(mySettings: _*)

}

确保您正在使用导入:

import com.earldouglas.xsbtwebplugin.PluginKeys._
import com.earldouglas.xsbtwebplugin.WebPlugin._

通过这些导入,您可以使用正确的密钥和配置:

port in container.Configuration := 9000

这在settings块中:

...
lazy val project = Project (
  "example",
  file("."),
  settings = Defaults.defaultSettings ++ ScalatraPlugin.scalatraWithJRebel ++ scalateSettings ++ Seq(
    port in container.Configuration := 9000,
    organization := Organization,
...

scalatra-sbt 建立在 xsbt-web-plugin 上,其设置记录在这里:https ://github.com/JamesEarlDouglas/xsbt-web-plugin/wiki/Settings

于 2013-07-27T13:58:18.493 回答
1

我这样做并工作:

....
val port = SettingKey[Int]("port")
val Conf = config("container")

lazy val project = Project (
    port in Conf := 8081,
    ....
)
于 2013-08-06T22:52:18.870 回答
0

我在项目的根目录中创建了一个空的 build.sbt 文件并放入:

port in container.Configuration := 8090

在文件中使其工作。

于 2014-07-03T19:06:11.723 回答