Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include jar file in Scala interpreter

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 *.jar 

But I would like to be able to include a jar file when running the interpreter.

like image 980
BefittingTheorem Avatar asked Nov 10 '09 12:11

BefittingTheorem


People also ask

Can Java JAR be used in Scala?

To run scala programs with the java command, you need to include the scala library as a runtime dependency of your application. I'm including the same Compile. jar from the java example as a compile time dependency, to show how everything behaves. The scala runtime is just a jar file (scala-library.

How do I use Scala interpreter?

To run Scala from the command-line, download the binaries and unpack the archive. Start the Scala interpreter (aka the “REPL”) by launching scala from where it was unarchived. Start the Scala compiler by launching scalac from where it was unarchived.

What is REPL Scala?

The Scala REPL (“Read-Evaluate-Print-Loop”) is a command-line interpreter that you use as a “playground” area to test your Scala code.


2 Answers

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)

like image 93
Eastsun Avatar answered Oct 20 '22 17:10

Eastsun


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

like image 26
Nikolay Ivanov Avatar answered Oct 20 '22 17:10

Nikolay Ivanov