使用 sbt 从代码启动 scala repl 循环 [英] Start scala repl loop from code using sbt

查看:52
本文介绍了使用 sbt 从代码启动 scala repl 循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试启动 scala repl 循环(使用 breakif)并且我正在从 SBT 构建/运行,并且我尝试遵循常见问题解答中的建议,但未能使其正常工作.

I'm trying to start a scala repl loop (using breakif) and I'm building/running from SBT and I've tried to follow the advice in the FAQ but haven't been able to get it to work.

有人可以举一个用于配置设置的 MyType 的示例,如所述,MyType 是一个代表类,应包含在解释器的类路径及其应用程序类加载器中"

Could someone give an example of the MyType which is being used to configure the settings as described, "MyType is a representative class that should be included on the interpreter's classpath and in its application class loader"

https://github.com/harrah/xsbt/wiki/FAQ (在如何在我的代码中使用 Scala 解释器?")

https://github.com/harrah/xsbt/wiki/FAQ (under "How do I use the Scala interpreter in my code?")

使用 Scala 2.9.1 和 sbt 0.11

Using scala 2.9.1 and sbt 0.11

谢谢

推荐答案

FAQ 链接到 背景讨论,它演示了 MyType 的实际使用方式,

The FAQ links to a background discussion, which demonstrates how MyType is actually used,

用法:

val settings = new Settings()
settings.embeddedDefaults[MyType]

SBT 内部:

def embeddedDefaults[T: Manifest] {
  val loader = implicitly[Manifest[T]].erasure.getClassLoader
  explicitParentLoader = Some(loader) // for the Interpreter parentClassLoader
  getClasspath("app", loader) foreach { classpath.value = _ }
  getClasspath("boot", loader) foreach {
     bootclasspath.value = settings.bootclasspath.value + File.separator + _
  }
}

所以 MyType 仅用于帮助 SBT 找到合适的类加载器.据推测,您可以选择 MyType 作为您希望从解释器中获得的项目中的任意类.这基本上就是常见问题解答的意思:MyType 是一个代表类,应该包含在解释器的类路径及其应用程序类加载器中.

So MyType is only used to help SBT find the appropriate classloader. Presumably, you can choose MyType to be an arbitrary class from your project that you want to have available from the interpreter. This is basically what the FAQ means when it says: MyType is a representative class that should be included on the interpreter's classpath and in its application class loader.

这篇关于使用 sbt 从代码启动 scala repl 循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆