Include jar file in Scala interpreter

Viewed 20575

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.

7 Answers

"lib/*.jar" generates a list with blank between items not ":" or ";" as required. Since Java 6 "lib/*" should work, but sometimes doesn't (classpath is set somewhere else)

I use a script like:

  1. Windows:

    @rem all *.jars in lib subdirectory
    
    @echo off
    
    set clp=.
    
    for %%c in (lib\*.jar) do call :Setclasspath %%c
    
    echo The classpath is %clp% 
    
    scala -classpath %clp% script.scala
    
    exit /B %ERRORLEVEL%
    
    :Setclasspath
    set clp=%clp%;%~1
    exit /B 0
    
  2. Linux:

    #!/bin/bash
    
    #all *.jars in lib subdirectory
    
    clp="."
    
    for file in lib/*
    do
      clp="$clp:$file"
    done
    
    echo $clp
    
    
    scala -classpath $clp script.scala
    
Related