1

When scala REPL starts some default packages like scala.lang._ , scala.Predef are automatically available.Suppose I have my own package like com.raghhuraamm.rUtils._

How to import this package automatically when REPL starts? Is there a way or I just have to type "import com.raghhuraamm.rUtils._ " every time I start scala REPL?

RAGHHURAAMM
  • 1,099
  • 7
  • 15
  • Please refer https://stackoverflow.com/questions/47874731/how-to-import-package-into-scala-repl – Chaitanya Jul 12 '18 at 08:42
  • @ChaitanyaWaikar Neither is this question about SBT, nor do the linked answers say anything about `import`ing packages automatically. – Andrey Tyukin Jul 12 '18 at 08:58

2 Answers2

1

If you could use sbt console to launch the REPL, you can create a build.sbt containing this line:

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

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

László van den Hoek
  • 3,955
  • 1
  • 23
  • 28
0

Create a script (myPreload.scala, say) that contains all the imports that you want:

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

Assuming that the classes are packaged in my.jar, start the scala repl as follows:

scala -cp path/to/my.jar -i some/other/path/to/myPreload.scala
Andrey Tyukin
  • 43,673
  • 4
  • 57
  • 93