Search code examples
scalaread-eval-print-loop

Scala REPL additional Jars


I am adding jars into my scala repl like so:

scala> :cp scalaj-http_2.10-2.2.1.jar
Added '/home/XXX/scalaj-http_2.10-2.2.1.jar'.  Your new classpath is:
".:/home/XXX/json4s-native_2.10-3.3.0.RC3.jar:/home/XXX/scalaj-http_2.10-2.2.1.jar"
Nothing to replay.

Now when I try and import that jar for use I get an error:

scala> import scalaj.http._
<console>:7: error: not found: value scalaj
       import scalaj.http._

I've tried this on another jar:

scala> :cp json4s-native_2.10-3.3.0.RC3.jar
Added '/home/XXX/json4s-native_2.10-3.3.0.RC3.jar'.  Your new classpath is:
".:/home/XXX/json4s-native_2.10-3.3.0.RC3.jar"
Nothing to replay.

scala> import org.json4s.JsonDSL._
<console>:7: error: object json4s is not a member of package org
       import org.json4s.JsonDSL._

I've read multuple tutorials online that all do it this way but my REPL does not seem to be behaving in the same manor. I am using Scala 2.10


Solution

  • Double check your path, if it still is not working you can try adding the jar at the time you start the REPL (it's always seemed to work for me, even with v2.10)

    scala -cp /home/XXX/json4s-native_2.10-3.3.0.RC3.jar:/home/XXX/scalaj-http_2.10-2.2.1.jar

    Note: That the delimeter between jars is ; for Windows and : otherwise.