【问题标题】:How to import an user defined package into scala REPL automatically when scala REPL is started?scala REPL启动时如何自动将用户定义的包导入scala REPL?
【发布时间】:2018-07-12 08:37:36
【问题描述】:

当 scala REPL 启动一些默认包时,例如 scala.lang._ , scala.Predef 自动可用。假设我有自己的包,如 com.raghhuraamm.rUtils._

REPL 启动时如何自动导入这个包?有没有 或者我只需要输入“import com.raghhuraamm.rUtils._” 我什么时候开始 scala REPL?

【问题讨论】:

标签: scala import


【解决方案1】:

如果您可以使用 sbt console 启动 REPL,您可以创建一个包含此行的 build.sbt

initialCommands in Compile in console += "import com.raghhuraamm.rUtils._"

来源:https://www.scala-sbt.org/1.x/docs/Inspecting-Settings.html

【讨论】:

    【解决方案2】:

    创建一个包含您想要的所有导入的脚本(例如myPreload.scala):

    // in myPreload.scala
    import com.raghhuraamm.rUtils._
    

    假设类打包在my.jar中,启动scala repl如下:

    scala -cp path/to/my.jar -i some/other/path/to/myPreload.scala
    

    【讨论】:

      猜你喜欢
      • 2018-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-19
      • 1970-01-01
      • 2014-08-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多