【问题标题】:How to interact with my play application in console?如何在控制台中与我的播放应用程序交互?
【发布时间】:2020-10-15 09:07:19
【问题描述】:

我有一个使用 scala 的 play 2.8.x 应用程序。

sbt 项目有一个 play web 项目和另一个库模块。

是否可以与 REPL 中的其他模块进行交互? 我的系统上也安装了 ammonite,但不知道如何加载我的模块。我只需要构建然后在我的 /target 构建文件夹中引用该库吗?还是有更好的办法?

我可以在 sbt 中单独执行此操作吗,或者 ammonite 是唯一的方法?

【问题讨论】:

    标签: scala playframework sbt ammonite


    【解决方案1】:

    每个 sbt 项目都有一个 REPL,你只需要运行:

    sbt> console
    

    用于根项目或name 项目

    sbt> name/console
    

    但这是正常的Scala REPL,如果你想要菊石,那么there is instruction on ammonite.io

    您也可以在现有的 SBT 项目中试用 Ammonite 2.1.4。为此,请将以下内容添加到您的 build.sbt

    libraryDependencies += {
      val version = scalaBinaryVersion.value match {
        case "2.10" => "1.0.3"
        case _ ⇒ "2.1.4"
      }
      "com.lihaoyi" % "ammonite" % version % "test" cross CrossVersion.full
    }
    
    sourceGenerators in Test += Def.task {
      val file = (sourceManaged in Test).value / "amm.scala"
      IO.write(file, """object amm extends App { ammonite.Main.main(args) }""")
      Seq(file)
    }.taskValue
    
    // Optional, required for the `source` command to work
    (fullClasspath in Test) ++= {
      (updateClassifiers in Test).value
        .configurations
        .find(_.configuration.name == Test.name)
        .get
        .modules
        .flatMap(_.artifacts)
        .collect{case (a, f) if a.classifier == Some("sources") => f}
    }
    

    之后,只需点击

    sbt projectName/test:run
    

    或者如果测试范围内还有其他主要方法

    sbt projectName/test:run-main amm 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-12
      • 2013-10-20
      相关资源
      最近更新 更多