micnap
February 27, 2018, 3:50pm
1
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?
curoli
February 27, 2018, 4:56pm
2
Hello,
You compile it and then put the resulting Test.class on the classpath when
you launch scala.
Best, Oliver
1 Like
micnap
February 27, 2018, 5:20pm
3
That was helpful. Thank you!
bmaso
February 27, 2018, 9:19pm
4
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