使用 sbt 从代码启动 scala repl 循环

编程入门 行业动态 更新时间:2024-10-26 04:22:38
本文介绍了使用 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"

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

github/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 循环

本文发布于:2023-07-24 13:18:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1203680.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:代码   sbt   repl   scala

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!