Include jar file in Scala interpreter

后端 未结 7 1068
囚心锁ツ
囚心锁ツ 2020-12-28 14:54

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         


        
相关标签:
7条回答
  • 2020-12-28 15:20

    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)

    0 讨论(0)
  • 2020-12-28 15:25

    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.
    
    0 讨论(0)
  • 2020-12-28 15:32

    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.

    0 讨论(0)
  • 2020-12-28 15:33

    Include multiple jars int Scala REPL 2.10.0-RC2

    scala -classpath my_1st.jar:my_2nd.jar:my_3rd.jar
    
    0 讨论(0)
  • 2020-12-28 15:34

    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
    
    0 讨论(0)
  • 2020-12-28 15:41

    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

    0 讨论(0)
提交回复
热议问题