Is it possible to include a jar file run running the Scala interpreter?
My code is working when I compile from scalac:
scalac script.scala -classpath
In scala2.8,you can use
scala>:jar JarName.jar
to add a jar to the classpath.
In Scala 2.8.1, it is not :jar but :cp
And in Scala 2.11.7 it is not :cp but :re(quire)
In Scala version 2.11.6 from scala REPL use :require
, can best be figured out by using :help
from REPL
For example:
$ scala
Welcome to Scala version 2.11.6 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_45).
Type in expressions to have them evaluated.
Type :help for more information.
scala> :require lift-json_2.11-3.0-M5-1.jar
Added '<path to lift json library>/lift-json/lift-json_2.11-3.0-M5-1.jar' to classpath.
Scala version 2.11.5:
Here is an example of adding all jars in your ivy cache:
scala -cp /Users/dbysani/.ivy2/cache/org.apache.spark/spark-streaming_2.10/jars/*
scala> import org.apache.spark.streaming.StreamingContext
import org.apache.spark.streaming.StreamingContext
You can also create a local folder of all the jars that you need to get added and add it in a similar way.
Hope this helps.
Include multiple jars int Scala REPL 2.10.0-RC2
scala -classpath my_1st.jar:my_2nd.jar:my_3rd.jar
in my case i am using Scala code runner version 2.9.2. and i had to add quotation marks. I am using this jar files:
jdom-b10.jar, rome-0.9.jar
and everything goes fine with this:
scala -classpath "*.jar" feedparser.scala
According to scala executable help all options of scalac are allowed ,
so you can run scala -classpath some.jar
, i've just tried and it looks like it works