Importing custom package into REPL

Complete newbie here. How do I make a custom package/class available in the REPL? I have the following saved in lesson7/Test.scala:

package lesson7

class Test {
val configA = "I am public"
private val configB = “I am private”

I need to make that available with:
scala> import lesson7.Test

Where exactly do I need to save lesson7/Test.scala in order to be able to import it like this?

Hello,

You compile it and then put the resulting Test.class on the classpath when
you launch scala.

Best, Oliver

1 Like

That was helpful. Thank you!

You might want to try the Ammonite REPL (ammonite.io). Its got some nice
features for importing Maven/Ivy artifacts and all transitive dependencies
from within the REPL. Very nice to work with.

Brian Maso

Given

$ cat gunk.scala

package gunk

object Main extends App {
  println("hello, world.")
}

then

scala> :paste gunk.scala
Pasting file gunk.scala...

scala> gunk.Main main null
hello, world.

In REPL, the distinction is between :load which works like line-by-line input and :paste which accepts package clauses.

1 Like